【发布时间】:2017-03-15 18:38:21
【问题描述】:
我想配置 clang-format 而不必将我的 .clang-format 文件复制到每个新工作区。
在我的settings.json 我目前有
"C_Cpp.clang_format_style": "{BasedOnStyle: Google, IndentWidth: 4, IndentCaseLabels: false, TabWidth: 4, UseTab: ForIndentation, ColumnLimit: 0}",
"C_Cpp.clang_format_fallbackStyle": "Google"
C_Cpp.clang_format_style 的描述是
编码风格,目前支持:Visual Studio、LLVM、Google、Chromium、Mozilla、WebKit。使用“文件”从当前或父目录中的 .clang 格式文件加载样式。使用“{key: value, ...}”设置具体参数,例如:“{ BasedOnStyle: LLVM, IndentWidth: 8 }”
这让我认为我的方法会奏效,但事实并非如此。当我使用自动格式时,它总是使用 Google fallbackStyle。
这是不可能的还是我在这里做错了什么?
【问题讨论】:
-
为了让 clang-format 运行,我大致做了以下事情(在我的脑海中,希望不会太错误):我安装并激活了 (!) xaver 的 Clang-Format 扩展,然后配置就像
"clang-format.style": "{BasedOnStyle: LLVM, IndentWidth: 2, Standard: Cpp11}"。 -
格式化程序将在文件系统中上升,直到它在某个祖先目录中找到
.clag-format或_clang.format。您可以将该文件放在 $HOME 目录中,每个项目都会使用它。
标签: visual-studio-code vscode-settings clang-format