VSCode 设置代码格式化

VSCode 设置代码格式化

文件->首选项->设置 然后右上角 打开设置(json)
在这里插入图片描述

默认设置:

{
    "editor.fontSize": 18,
    "merge-conflict.codeLens.enabled": false,
    "editor.unicodeHighlight.includeStrings": false,
    "editor.unicodeHighlight.includeComments": false,
    "editor.unicodeHighlight.nonBasicASCII": false,
    "diffEditor.ignoreTrimWhitespace": false,
    "[javascript]": {
        "editor.defaultFormatter": "vscode.typescript-language-features"
    }
}

规则1:

{
    "git.autofetch": true,
    "editor.quickSuggestions": {
    "strings": true
    },
    "files.autoSave": "afterDelay",
    // vetur configuration
    "vetur.format.defaultFormatter.html": "js-beautify-html",
    "vetur.format.defaultFormatter.js": "prettier",
    "vetur.format.defaultFormatter.css": "prettier",
    "vetur.format.defaultFormatter.ts": "prettier",
    "vetur.format.defaultFormatterOptions": {
    // 属性强制折行对齐
    "wrap_attributes": "force-aligned"
    },
    // eslint configuration
    "eslint.enable": true,
    "eslint.autoFixOnSave": true,
    "eslint.validate": [
    {
    "language": "html",
    "autoFix": true
    },
    {
    "language": "vue",
    "autoFix": true
    },
    {
    "language": "css",
    "autoFix": true
    },
    {
    "language": "scss",
    "autoFix": true
    },
    {
    "language": "typescript",
    "autoFix": true
    },
    {
    "language": "javascript",
    "autoFix": true
    },
    {
    "language": "javascriptreact",
    "autoFix": true
    }
    ],
    "explorer.confirmDelete": true,
    "vetur.validation.template": false,
    "editor.fontSize": 16,
    "window.zoomLevel": 0,
    "editor.minimap.enabled": false,
    "workbench.startupEditor": "newUntitledFile",
    "editor.codeActionsOnSave": {
        "source.fixAll.eslint": true
    },
    "files.associations": {
        "*.cjson": "jsonc",
        "*.wxss": "css",
        "*.wxs": "javascript"
    },
    "emmet.includeLanguages": {
        "wxml": "html"
    },
    "minapp-vscode.disableAutoConfig": true,
    "workbench.colorTheme": "Visual Studio Dark",
    "javascript.updateImportsOnFileMove.enabled": "never",
}

规则2:

{
  "files.eol": "\n",
  "typescript.preferences.quoteStyle": "single",
  "javascript.preferences.quoteStyle": "single",
  // tab 大小为2个空格
  "editor.tabSize": 2,
  // 编辑器换行
  "editor.wordWrap": "off",
  // 保存时格式化
  "editor.formatOnSave": false,
  // 开启 vscode 文件路径导航
  "breadcrumbs.enabled": true,
  // prettier 设置语句末尾不加分号
  "prettier.semi": false,
  // prettier 设置强制单引号
  "prettier.singleQuote": true,
  // 选择 vue 文件中 template 的格式化工具
  "vetur.format.defaultFormatter.html": "js-beautify-html",
  // vetur 的自定义设置
  "vetur.format.defaultFormatterOptions": {
    "js-beautify-html": {
      "wrap_attributes": "aligned-multiple"
    },
    "prettier": {
      "singleQuote": true,
      "semi": false,
      "printWidth": 100,
      "wrapAttributes": false,
      "sortAttributes": false
    }
  }
}

推荐使用规则2

### VSCode 中 C++ 代码格式化的插件及配置方法 在 Visual Studio Code (VSCode) 中对 C++ 代码进行格式化,可以通过安装特定的插件并完成相应的配置来实现。以下是详细的说明: #### 插件推荐 为了实现高效的代码格式化功能,可以使用以下两个主要插件: - **C/C++ Clang Command Adapter**: 提供了强大的代码格式化支持,并允许用户自定义格式化规则[^1]。 - **Clang-Format**: 这是一个官方推荐的工具,用于自动化代码样式调整。它通常随 C/C++ 扩展一起安装[^2]。 #### 配置步骤详解 ##### 安装必要的扩展 1. 在 VSCode 的扩展市场中搜索 `C/C++` 并安装由 Microsoft 提供的官方扩展。 2. 同时确保已安装 `Clang-Format` 或其他兼容的格式化程序插件。 ##### 设置默认格式化器 1. 打开 VSCode设置界面 (`Ctrl+,`)。 2. 使用搜索框查找 `"Default Formatter"`。 3. 将其值更改为 `ms-vscode.cpptools` 或所选的具体格式化器名称。 ##### 开启保存时自动格式化 1. 继续在设置页面中搜索关键字 `"format on save"` 和 `"format on type"`。 2. 勾选这两个选项以启用保存或键入时触发代码格式化的行为。 ##### 自定义格式化风格 如果希望进一步定制代码格式化的效果,则需创建 `.clang-format` 文件: 1. 导航至项目根目录下的路径 `/vscode/extensions/ms-vscode.cpptools-<version>/LLVM/bin/`[^3]。 2. 在该位置执行命令 `clang-format -style=<StyleName> -dump-config > .clang-format` 来生成预设样式的配置文件。其中 `<StyleName>` 可以为 Google, LLVM, Mozilla 等标准之一。 例如,采用谷歌编码规范可运行如下脚本: ```bash clang-format -style=Google -dump-config > .clang-format ``` ##### 处理特殊场景——注释块格式化 尽管 `.clang-format` 已经非常强大,但它可能无法完美处理某些复杂的多行注释结构[^4]。此时建议额外引入辅助插件如 **Auto Comment Blocks**,它可以增强注释管理能力。当开发者输入 `/**` 符号后按下回车键,此插件能够智能延续星号排列,从而提升用户体验。 ```python def example_function(): """ This is an auto-generated comment block. Each new line starts with a star automatically when using the 'Auto Comment Blocks' plugin. """ pass ``` 以上即是在 VSCode 下针对 C++ 编程语言实施高效代码格式化的完整解决方案。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值