vscode类工具自动对齐

//使用下面这个可以在自动对齐的基础上更美观

下面的要在vscode的设置中搜索C_Cpp.clang_format_style ,然后随便找个路径定义.clang-format的文件,复制下面的,然后在C_Cpp.clang_format_style这个的配置项中 输入file:自己的盘:\自己的路径.clang-format

`---

Visual Studio 样式类似于:

C_Cpp.clang_format_style file:D:\APP\VScode\path\file.clang-format

代码风格配置文件,用于指导代码的格式化和排版,以保持代码的一致性和可读性。

Language: Cpp

基于LLVM代码风格进行配置,这是一种广泛采用的C++代码风格。

BasedOnStyle: LLVM

禁止使用制表符,而是使用空格进行缩进,以避免不同编辑器间显示格式的差异。

UseTab: Never

指定每个缩进层级使用4个空格,这是大多数C++代码风格的常见选择。

IndentWidth: 4

制表符的宽度设置为4个空格,与IndentWidth保持一致,确保使用制表符和空格混合缩进时的显示效果一致。

TabWidth: 4

按照Allman风格,函数和控制流结构的左花括号另起一行,以增强代码的可读性。

BreakBeforeBraces: Allman # 我们将结构体花括号放在同一行,以提高代码的可读性。

禁止将if语句(不包括else子句)放在一行内,以提高代码的可读性和可维护性。

AllowShortIfStatementsOnASingleLine: false

不对case标签进行额外缩进,保持与switch语句的左花括号对齐,以清晰显示控制流结构。

IndentCaseLabels: false

不设置列限制,允许代码自由扩展,注重代码的可读性而不强制限制行宽。

ColumnLimit: 90

访问修饰符(public、private、protected)的前面添加-4个空格的缩进,以区分于类成员的缩进。

AccessModifierOffset: -4

对所有命名空间层级进行缩进,以清晰显示命名空间的嵌套关系。

NamespaceIndentation: All

不修正命名空间注释的缩进,保持原始格式。

FixNamespaceComments: false

长度差异过大时,比如上面是结构体,下面是int就加个空行

对齐连续声明

AlignConsecutiveDeclarations: true

对齐连续的赋值语句

AlignConsecutiveAssignments:
Enabled: true
AcrossEmptyLines: true
AcrossComments: true
AlignConsecutiveMacros: AcrossEmptyLinesAndComments

...
`

//使用这个复制在设置可以配置自动对齐

{
  "files.autoSave": "afterDelay",
  "files.autoGuessEncoding": true,
  "workbench.list.smoothScrolling": true,
  "editor.cursorSmoothCaretAnimation": "on",
  "editor.smoothScrolling": true,
  "editor.cursorBlinking": "smooth",
  "editor.mouseWheelZoom": true,
  "editor.formatOnPaste": true,
  "editor.formatOnType": true,
  "editor.formatOnSave": true,
  "editor.wordWrap": "on",
  "editor.guides.bracketPairs": true,
  //"editor.bracketPairColorization.enabled": true, (此设置vscode在较新版本已默认开启)
  "editor.suggest.snippetsPreventQuickSuggestions": false,
  "editor.acceptSuggestionOnEnter": "smart",
  "editor.suggestSelection": "recentlyUsed",
  "window.dialogStyle": "custom",
  "debug.showBreakpointsInOverviewRuler": true,
}

例如我自己的配置

{
  "workbench.colorTheme": "GitHub Light",
  "files.autoGuessEncoding": true,
  "workbench.list.smoothScrolling": true,
  "editor.cursorSmoothCaretAnimation": "on",
  "editor.smoothScrolling": true,
  "editor.cursorBlinking": "smooth",
  "editor.mouseWheelZoom": true,
  "editor.formatOnType": true,
  "editor.wordWrap": "on",
  "editor.guides.bracketPairs": true,
  //"editor.bracketPairColorization.enabled": true, (此设置vscode在较新版本已默认开启)
  "editor.suggest.snippetsPreventQuickSuggestions": false,
  "editor.acceptSuggestionOnEnter": "smart",
  "editor.suggestSelection": "recentlyUsed",
  "window.dialogStyle": "custom",
  "debug.showBreakpointsInOverviewRuler": true,
  "python.defaultInterpreterPath": "c:\\msys64\\ucrt64\\bin\\python.exe",
  "KeilAssistant.MDK.Uv4Path": "D:\\APP\\MDK\\Core\\UV4\\UV4.exe",
  "pyqt-integration.qtdesigner.path": "D:\\APP\\python\\Lib\\site-packages\\PySide6\\designer.exe",
  "pyqt-integration.pyrcc.cmd": "D:\\APP\\python\\Scripts\\pyside6-rcc.exe",
  "pyqt-integration.pyuic.cmd": "D:\\APP\\python\\Scripts\\pyside6-uic.exe",
  "workbench.editor.enablePreview": false,
  "explorer.confirmDelete": false,
  "editor.formatOnPaste": true,
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.formatOnSave": true,
  "[c]": {
    "editor.defaultFormatter": "ms-vscode.cpptools",
  },
  "idf.hasWalkthroughBeenShown": true,
  "idf.showOnboardingOnInit": false,
  "idf.espIdfPathWin": "d:\\APP\\ESPIDF553\\Espressif\\frameworks\\esp-idf-v5.5.3",
  "idf.toolsPathWin": "d:\\APP\\ESPIDF553\\Espressif",
  "idf.gitPathWin": "d:\\APP\\ESPIDF553\\Espressif\\tools\\idf-git\\2.39.2\\cmd\\git.exe",
  "idf.pythonInstallPath": "d:\\APP\\ESPIDF553\\Espressif\\tools\\idf-python\\3.11.2\\python.exe",
  "claudeCode.preferredLocation": "panel",
  "workbench.editor.empty.hint": "hidden",
  "files.autoSave": "afterDelay",
  "editor.minimap.enabled": false,
  "C_Cpp.clang_format_style": "file:D:\\APP\\VScode\\path\\file\\.clang-format",
}
```[]()

posted on 2026-07-07 21:10  li5920o  阅读(2)  评论(0)    收藏  举报

导航