

Vscode配置clang-Format的tabWidth
source link: https://shingle.me/post/vscode%E9%85%8D%E7%BD%AEclang-format%E7%9A%84tabwidth/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Vscode配置clang-Format的tabWidth
接着上上篇 Vscode配置proto插件, 在装了 clang-format插件后,我发现格式化完的 proto 文件tabwidth 默认为2, 看起来很别扭
网上搜索得到的大部分解决方案是: 修改 vscode 里的C_Cpp.clang_format_fallbackStyle
配置, 该配置的默认值为Visual Studio
,改为 Google
或者LLVM
"C_Cpp.clang_format_fallbackStyle":"Google"
这个修改解决的是{}
花括号会换行的格式问题,
//不换行
func a{
}
//会换行
func a
{
}
可能是vscode 已经默认使用了左花括号不换号的行为, 所以修改了这个选项并没有任何反应.
还有人提出可以在该设置中添加额外选项:
"C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: Google, IndentWidth: 4, TabWidth: 4 }"
经测试发现也没有效果, 我甚至把clang-format
能设置的选项都加上了
其实很简单, 新建一个~/.clang-format
文件,添加一行, 在格式化时clang-format
会默认使用该配置文件
IndentWidth: 4
是我想要的效果是四个空格的缩进
Recommend
-
65
VSCode 已经成了我的主力编辑器,包括用来写 C++。虽然默认的 cpptools 插件已经很好用了,但 cquery 插件更加强大,极力推荐。 cquery 是基于 LSP(Language-Server-P...
-
37
安装Go语言调试工具dlv 前提 需要安装Xcode命令行工具。运行以下命令安装: xcode-select --install dlv安装 go install github.com/derekparker/delve/cmd/dlv 配置...
-
10
Let’s benchmark toupper implementations. Actually, I don’t really care about toupper much at all, but I was writing...
-
11
Summary: The Wuffs compiler outputs C code. When compiling its standard library, over 93% of the time (2.680 out of 2.855 seconds) was spent formatting that C code with clang-format . dumbindent...
-
8
Clang-format Tanks Performance Nov 19, 2019 This article is also available in Russian. Let’s benchmark
-
13
ESLint + VSCode: How to Format Your Code Using .eslintrc April 07, 2021I’ve gotten very used to having VSCode autoformat my file when I save. Usually, I use Prettier. But I joined a project that uses ESLint to manage...
-
12
Python Auto-Format HTML Templates in Django with VSCode Posted by Bernhard Knasmüller Octob...
-
3
Enforce code consistency with clang-format Skip to main content Imposing a common coding style can...
-
4
使用clang-format在CI中自动格式化C++代码 2022/07/30
-
13
vscode C++ 开发之使用 clangd、C/C++、clang-format ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK