VSC中clang-format设置函数括号风格

目前发现一个问题在通过clang-format保存自动格式化时,函数的括号风格老是变化,一会是后置风格,一会是另起一行,如下所示:
风格1:

void fun(void){

}

风格2:

void fun(void)
{

}

本人想统一为风格1,无耐在VSC的UI里面各种参数尝试无果,于是找到官网:

ClangFormatStyleOptions

找到相关的设置:

BraceWrapping (BraceWrappingFlags)
Control of individual brace wrapping cases.

If BreakBeforeBraces is set to BS_Custom, use this to specify how each individual brace case should be handled. Otherwise, this is ignored.

# Example of usage:
BreakBeforeBraces: Custom
BraceWrapping:
  AfterEnum: true
  AfterStruct: false
  SplitEmptyFunction: false
  afterFunction: true

其中设置函数后括号风格的:

bool AfterFunction Wrap function definitions.

true:
void foo()
{
  bar();
  bar2();
}

false:
void foo() {
  bar();
  bar2();
}

将以上的配置添加到.clang-format 文件中,放到VSC工程的根目录下,才能生效

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注