文章目录
配置 settings.json 文件
将以下内容复制到 settings.json
文件中,该文件通常位于 xxx/Code/User
目录下。您可以使用 VS Code 打开该文件,或者通过命令行编辑。
{
// 编辑器设置
"editor.tabSize": 2,
"editor.fontSize": 18,
"editor.formatOnSave": false,
"editor.renderWhitespace": "all",
"editor.rulers": [
120
],
"editor.quickSuggestions": {
"comments": false,
"other": true,
"strings": false
},
"editor.accessibilitySupport": "on",
// 文件管理
"files.autoSave": "onFocusChange",
"files.autoSaveDelay": 1000,
"files.defaultLanguage": "plaintext",
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"files.trimTrailingWhitespace": true,
// 安全性
"security.workspace.trust.untrustedFiles": "open",
// 扩展和建议
"extensions.ignoreRecommendations": true,
// Git 设置
"git.confirmSync": false,
// C/C++ 设置
"cpplint.cpplintPath": "/usr/local/bin/cpplint",
"cpplint.lineLength": 120,
"cpplint.verbose": 1,
"cpplint.filters": [
"-runtime/references",
"-build/include_subdir",
"-build/c++11",
"-build/c++14",
"-build/header_guard",
"+build/include_what_you_use"
],
"C_Cpp.vcFormat.indent.accessSpecifiers": true,
"C_Cpp.vcFormat.indent.braces": true,
"C_Cpp.vcFormat.indent.caseContentsWhenBlock": true,
"C_Cpp.vcFormat.indent.caseLabels": true,
"C_Cpp.formatting": "clangFormat",
"C_Cpp.clang_format_path": "/usr/bin/clang-format",
"C_Cpp.clang_format_sortIncludes": true,
"C_Cpp.clang_format_style": "{ BasedOnStyle: Google, IndentWidth: 2, ColumnLimit: 120, AllowShortFunctionsOnASingleLine: false }",
"C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: Google, IndentWidth: 2, ColumnLimit: 120, AllowShortFunctionsOnASingleLine: false }",
"C_Cpp.default.cStandard": "c11",
"C_Cpp.default.cppStandard": "c++14",
"C_Cpp.intelliSenseEngineFallback": "enabled",
"C_Cpp.configurationWarnings": "disabled",
"C_Cpp.files.exclude": {
"**/.vscode": true,
"**/.vs": true,
"thirdparty/**": true,
"3dparty/**": true
},
// CMake 设置
"cmake.configureOnEdit": false,
"cmake.configureOnOpen": false,
"cmake.showOptionsMovedNotification": false,
// GitHub Copilot 设置
"github.copilot.enable": {
"*": true,
"plaintext": false,
"markdown": false,
"scminput": false,
"cpp": true
},
"github.copilot.editor.enableAutoCompletions": true,
// 可访问性设置
"accessibility.signals.volume": 0,
"accessibility.verbosity.notification": false,
"accessibility.signals.lineHasFoldedArea": {
"sound": "off"
},
"accessibility.signals.lineHasBreakpoint": {
"sound": "off"
},
"accessibility.signals.lineHasInlineSuggestion": {
"sound": "off"
},
"accessibility.signals.taskCompleted": {
"sound": "off"
},
"accessibility.signals.notebookCellFailed": {
"sound": "off"
},
"accessibility.signals.diffLineInserted": {
"sound": "off"
},
"accessibility.signals.diffLineDeleted": {
"sound": "off"
},
"accessibility.signals.diffLineModified": {
"sound": "off"
},
"accessibility.signals.lineHasWarning": {
"sound": "off",
"announcement": "off"
},
"accessibility.signals.lineHasError": {
"sound": "off",
"announcement": "off"
},
"accessibility.signals.progress": {
"sound": "off"
},
// 终端设置
"terminal.integrated.enableMultiLinePasteWarning": "never",
"terminal.integrated.fontFamily": "monospace",
// GitLens 设置
"gitlens.showWelcomeOnInstall": false,
"gitlens.showWhatsNewAfterUpgrades": false,
"gitlens.hovers.pullRequests.enabled": false,
// 用户界面设置
"workbench.sideBar.location": "left",
"workbench.colorCustomizations": {
"tab.activeBackground": "#0004ff"
},
"workbench.iconTheme": "vs-minimal",
"workbench.editor.enablePreview": false,
// 其他设置
"window.zoomLevel": 2,
"editor.minimap.enabled": false
}
配置 keybindings.json 文件
将以下内容复制到 keybindings.json
文件中,以自定义键绑定。您可以在 VS Code 中打开命令面板(Ctrl+Shift+P
),搜索并选择“Preferences: Open Keyboard Shortcuts (JSON)”来编辑该文件。
// Place your key bindings in this file to overwrite the defaults
[
{
"key": "ctrl+d",
"command": "editor.action.deleteLines",
"when": "textInputFocus && !editorReadonly"
},
{
"key": "alt+left",
"command": "workbench.action.navigateBack",
"when": "canNavigateBack"
},
{
"key": "alt+right",
"command": "workbench.action.navigateForward",
"when": "canNavigateForward"
},
{
"key": "shift+alt+u",
"command": "editor.action.transformToUppercase"
},
{
"key": "tab",
"command": "-insertSnippet",
"when": "editorTextFocus && hasSnippetCompletions && !editorTabMovesFocus && !inSnippetMode"
},
{
"key": "tab",
"command": "-jumpToNextSnippetPlaceholder",
"when": "editorTextFocus && hasNextTabstop && inSnippetMode"
},
{
"key": "tab",
"command": "-editor.emmet.action.expandAbbreviation",
"when": "config.emmet.triggerExpansionOnTab && editorTextFocus && !editorReadonly && !editorTabMovesFocus"
},
{
"key": "alt+q",
"command": "C_Cpp.SwitchHeaderSource",
"when": "editorTextFocus && editorLangId == 'c' || editorTextFocus && editorLangId == 'cc' || editorTextFocus && editorLangId == 'cpp' || editorTextFocus && editorLangId == 'cuda-cpp'"
},
{
"key": "shift+alt+f",
"command": "references-view.findReferences",
"when": "editorHasReferenceProvider"
},
{
"key": "alt+o",
"command": "-clangd.switchheadersource",
"when": "editorTextFocus"
},
{
"key": "alt+o",
"command": "-extension.switcher.doSwitch"
},
{
"key": "ctrl+alt+o",
"command": "-extension.switcher.doSwitchInWorkspaceRoot"
},
]
安装clang-format和cpplint的简明指南
Ubuntu
安装clang-format
通过包管理器安装:
sudo apt update
sudo apt install clang-format
安装cpplint
使用pip安装:
sudo apt update
sudo apt install python3-pip
pip3 install cpplint
Windows
安装clang-format
-
下载并安装LLVM:从 LLVM下载页面 获取适合您系统的安装程序(例如,llvm--win64.exe),运行安装程序。
-
设置环境变量:将LLVM的bin目录(例如,
C:\Program Files\LLVM\bin
)添加到系统的Path环境变量中。
安装cpplint
-
安装Python和pip:从 Python官网 下载并安装Python,确保选中“Add Python to PATH”选项。
-
使用pip安装cpplint:
pip install cpplint