clang-format 格式化工具简易配置
来源:互联网 发布:mysql execute into 编辑:程序博客网 时间:2024/06/07 05:31
安装就不说了。
格式化风格可使用内置风格或使用参数文件指定风格:
$ clang-format -style=LLVM -i test.cc # -style参数指定所选风格,可选项为 LLVM、Google、Chromium、Mozilla、WebKit 和 file,其中 file 指定参数文件。-i 表示将格式化后的内容写入原文件
若在当前目录或祖先目录中已有 .clang-format 文件,则可直接
$ clang-format -i test.cc
.clang-format 可使用如下命令生成:
$ clang-format -style=llvm -dump-config > .clang-format
然后修改参数,以适应自己的要求。我习惯了 Linux kernel 风格,要修改以下几项:
BasedOnStyle: LLVMColumnLimit: 120 # 每行最多显示120个字符Standard: Cpp11IndentWidth: 4TabWidth: 4UseTab: AlwaysBreakBeforeBraces: LinuxAllowShortIfStatementsOnASingleLine: falseIndentCaseLabels: falseAllowShortFunctionsOnASingleLine: Inline
CentOS 7 上修改后的内容如下:
---# BasedOnStyle: LLVMAccessModifierOffset: -2ConstructorInitializerIndentWidth: 4AlignEscapedNewlinesLeft: falseAlignTrailingComments: trueAllowAllParametersOfDeclarationOnNextLine: trueAllowShortIfStatementsOnASingleLine: falseAllowShortLoopsOnASingleLine: falseAllowShortFunctionsOnASingleLine: NoneAlwaysBreakTemplateDeclarations: falseAlwaysBreakBeforeMultilineStrings: falseBreakBeforeBinaryOperators: falseBreakBeforeTernaryOperators: trueBreakConstructorInitializersBeforeComma: falseBinPackParameters: trueColumnLimit: 120ConstructorInitializerAllOnOneLineOrOnePerLine: falseDerivePointerBinding: falseExperimentalAutoDetectBinPacking: falseIndentCaseLabels: falseMaxEmptyLinesToKeep: 1NamespaceIndentation: NoneObjCSpaceBeforeProtocolList: truePenaltyBreakBeforeFirstCallParameter: 19PenaltyBreakComment: 60PenaltyBreakString: 1000PenaltyBreakFirstLessLess: 120PenaltyExcessCharacter: 1000000PenaltyReturnTypeOnItsOwnLine: 60PointerBindsToType: falseSpacesBeforeTrailingComments: 1Cpp11BracedListStyle: falseStandard: Cpp11IndentWidth: 4TabWidth: 4UseTab: AlwaysBreakBeforeBraces: LinuxIndentFunctionDeclarationAfterType: falseSpacesInParentheses: falseSpacesInAngles: falseSpaceInEmptyParentheses: falseSpacesInCStyleCastParentheses: falseSpaceAfterControlStatementKeyword: trueSpaceBeforeAssignmentOperators: trueContinuationIndentWidth: 4...
具体参数设置参考:http://clang.llvm.org/docs/ClangFormatStyleOptions.html
vscode 只需在用户设置里面加一行:
"C_Cpp.clang_format_style": "{ BasedOnStyle: LLVM, AllowShortFunctionsOnASingleLine: Inline, AlwaysBreakTemplateDeclarations: true, SpaceAfterTemplateKeyword: false, ColumnLimit: 120, Standard: Cpp11, IndentWidth: 4, TabWidth: 4, UseTab: Always, BreakBeforeBraces: Linux }",
阅读全文
0 0
- clang-format 格式化工具简易配置
- Clang-Format格式化选项介绍
- vim 配置 clang-format
- clang-format
- .clang-format
- 使用clang-format对iOS项目代码进行格式化
- 使用clang-format对iOS项目代码进行格式化
- 简易C程序格式化工具
- Ubuntu下clang开发工具简易入门知识(一)
- sublime JS Format js格式化工具
- clang-format中文出错
- Linux下的代码格式工具详解(indent, clang-format, astyle)
- 代码格式化工具Astyle配置
- RMAN的CONFIGURE配置和FORMAT字符串格式化!!!
- RMAN的CONFIGURE配置和FORMAT字符串格式化!!!
- Sublime Text 3 安装 Clang Format 插件
- Clang-Format的使用及其自定义格式
- Clang-Format-Options 中文翻译 (未完待续)
- CentOS 7常用工具安装
- nginx 多层代理 参数丢失
- Cows POJ
- android LayoutInflater
- Struts2(十三):超链接实现动态加载国际化资源文件
- clang-format 格式化工具简易配置
- 第四篇 :微信公众平台开发实战Java版之完成消息接受与相应以及消息的处理
- Android-UI 超级优良超级多超级强大开源控件源码demo
- Http协议中访问的状态码
- 第3章 Raster Images
- Oracle 11g RAC搭建(VMware环境)
- 章鱼体验第一天:思杰VDI之7.14.1
- win7下修改php.ini的配置路径
- C++之以独立语句将newed对象置入智能指针(17)---《Effective C++》