clang-format 命令行允许定义缩进宽度,例如
clang-format -style="{IndentWidth: 4}" myfile.cpp
我在 Ubuntu linux 上安装了 VSCode 的 clang-format 扩展,我在扩展配置中没有看到缩进配置。
有没有办法让扩展名缩进4?
简短的解决方案:在项目根目录创建一个
.clang-format
,其中包含以下内容:
# .clang-format
IndentWidth: 4
vscode-clang-format 似乎没有维护,但是,vscode 的 clangd 扩展附带了默认的格式化程序支持。根据 clangd 存储库的 README,格式由项目根目录下的
.clang-format
文件控制。这是文档,以防您需要。
可能有点晚了,但希望这会有所帮助。
在 clang-format 扩展设置中,您可以使用“Clang-format: Style”来给出特定选项。
示例:
{缩进宽度:4}