首页 > 解决方案 > Clang 格式结构初始化 - 缩进两个空格?

问题描述

我正在尝试使用 clang-format 格式化 C 文件。我希望缩进是两个空格字符,除了在全局变量结构初始化中之外,它主要工作。为此,它继续生成以四个空格缩进的行。

这是我的 .clang 格式文件

BasedOnStyle: LLVM
ColumnLimit: '80'
IndentWidth: '2'

clang-format 产生了这个令人惊讶的输出

typedef struct {
  int x;
} foo;

static foo bar{
    1, // This line is being indented with 4 spaces!
};

这就是我期望文件的样子:

typedef struct {
  int x;
} foo;

static foo bar{
  1, // This line is being indented with 2 spaces!
};

我尝试对 使用几个不同的值ConstructorInitializerIndentWidth,但该字段似乎不会影响此模式。

有没有我可以提供的设置来获得这种行为?

标签: clang-format

解决方案


试试ContinuationIndentWidth: 2。当我遇到这个问题时,这对我有用。


推荐阅读