VSC下clang-format的代码换行宽度设置

遇到的问题:clang-format  启动自动格式化后,每次自动换行的宽度太窄,导致大量的自动换行,影响代码美观。

解决:

以默认的.clang-format 配置文件为模板,修改ColumnLimit参数:

Language: Cpp
ColumnLimit: 120

最后将.clang-format  文件放到工程的根目录下,重新开启VSC,生效。
其中 Language的设置如下:

Language (LanguageKind)
Language, this format style is targeted at.

Possible values:

LK_None (in configuration: None) Do not use.
LK_Cpp (in configuration: Cpp) Should be used for C, C++.
LK_Java (in configuration: Java) Should be used for Java.
LK_JavaScript (in configuration: JavaScript) Should be used for JavaScript.
LK_ObjC (in configuration: ObjC) Should be used for Objective-C, Objective-C++.
LK_Proto (in configuration: Proto) Should be used for Protocol Buffers (https://developers.google.com/protocol-buffers/).
LK_TableGen (in configuration: TableGen) Should be used for TableGen code.
LK_TextProto (in configuration: TextProto) Should be used for Protocol Buffer messages in text format (https://developers.google.com/protocol-buffers/).

相关的选项含义可以参考这里:http://releases.llvm.org/3.6.0/tools/clang/docs/ClangFormatStyleOptions.html

发表回复

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