1 VSCode 添加clang-format扩展
2 在用户配置内添加:
"clang-format.executable": "C:\\Program Files\\LLVM\\bin\\clang-format.exe",
"editor.formatOnSave": true,
"clang-format.style": "Google",
"extensions.ignoreRecommendations": true
Clang-Format可用于格式化(排版)多种不同语言的代码,其自带的排版格式主要有:LLVM, Google, Chromium, Mozilla, WebKit。
如果自带的这几种排版格式可能并不满足个人编码习惯的全部要求,Clang-Format也提供了使用自定义排版格式的功能。
导出默认的排版模式配置,在默认的排版配置文件上修改:
clang-format -style=格式名 -dump-config > 文件名
其中,格式名的取值可以为llvm, google, chromium, mozilla, webkit中的任一种;文件名可以取任何名字,一般取.clang-format或_clang-format,因为自定义的排版格式文件只有取这两种名字之一,才能被Clang-Format识别。
具体配置可参考博文:
Clang 配置项说明