vscode配置使用 cpplint和clang-format

配置 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
  1. 下载并安装LLVM:从 LLVM下载页面 获取适合您系统的安装程序(例如,llvm--win64.exe),运行安装程序。

  2. 设置环境变量:将LLVM的bin目录(例如,C:\Program Files\LLVM\bin)添加到系统的Path环境变量中。

安装cpplint
  1. 安装Python和pip:从 Python官网 下载并安装Python,确保选中“Add Python to PATH”选项。

  2. 使用pip安装cpplint:

pip install cpplint
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

橘色的喵

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值