参考链接:
Clang-Format 用法详解
https://blog.youkuaiyun.com/wan212000/article/details/131709197
# 左花括号后面不换行
BreakBeforeBraces: Attach
# 缩进
IndentWidth: 4
# 行宽,不自动换行
ColumnLimit: 0
在设置界面,Extensions
> C/C++
> Formatting
中设置
最小更改
VSCode默认
Clang_format_fallback_Style
:Visual Studio
不变,
Clang_format_style
:file
, 默认不变
Use file to load the style from a
.clang-format
filein the current or parent directory
, or use file:<path>/.clang-format
to reference a specific path. Use{key: value, ...}
to set specific parameters. For example, the Visual Studio style is similar to:{ BasedOnStyle: LLVM, UseTab: Never, IndentWidth: 4, TabWidth: 4, BreakBeforeBraces: Allman, AllowShortIfStatementsOnASingleLine: false, IndentCaseLabels: false, ColumnLimit: 0, AccessModifierOffset: -4, NamespaceIndentation: All, FixNamespaceComments: false }
.
另外在settings.json中增加 else
后不换行
"C_Cpp.vcFormat.newLine.beforeElse": false
在git diff editor中,忽略空白字符,(这个做的没有idea系列好,idea可以忽略中间位置的空白字符)
"diffEditor.ignoreTrimWhitespace": true,
设置后格式化代码如下
if (is_xx) {
xxstop();
} else {
xxstop();
i++;
printf("%d....\n", i);
}