source insight 4.0 对c/c++ 代码格式化 clang-format

安装 clang-format

在 LLVM Download Page 中下载 Windows 版本并安装

需要注意选择 Add LLVM to the system PATH for current user 或 Add LLVM to the system PATH for all users 其中的一项

安装完成后,在命令行中测试:

clang-format -version

 

  1. 打开 Tools-> Custom Commands
  2. 点击 Add... 按钮,具体内容为:
    • Command 值为 clang-format for current file
    • Run 值为 clang-format --style=file -i %f
    • Dir 留空(即项目目录,这个目录里需要有 .clang-format 文件)
    • 勾选 Save Files First
    • 不要勾选 Pause When Done
    • 勾选 Wait Until Done
  3. 点击 Menu... 按钮,在合适的菜单中加入刚刚定义的命令(可选),例如在tools中,insert ,然后就可以在tools菜单中看到clang-format选项,点击后会格式化当前源文件
  4. 点击 Keys... 按钮,为刚刚定义的命令分配合适的快捷键(可选)

 

linux 下使用方法为:clang-format -i xxx.cpp

左括号的配置参考:https://clang.llvm.org/docs/ClangFormatStyleOptions.html  BreakBeforeBraces 

 

#基于那个配置文件
BasedOnStyle: Chromium
#指针的*的挨着哪边
#PointerAlignment: Right
#缩进宽度
IndentWidth: 4
# 连续的空行保留几行
MaxEmptyLinesToKeep: 1
# 在 @property 后面添加空格, \@property (readonly) 而不是 \@property(readonly).
#ObjCSpaceAfterProperty: true
# OC block后面的缩进
#ObjCBlockIndentWidth: 4
# 是否允许短方法单行
#AllowShortFunctionsOnASingleLine: true
# 是否允许短if单行 If true, if (a) return; 可以放到同一行
AllowShortIfStatementsOnASingleLine: true
#注释对齐
AlignTrailingComments: true
# 换行的时候对齐操作符
#AlignOperands: true
# 中括号两边空格 []
#SpacesInSquareBrackets: true
# 小括号两边添加空格
SpacesInParentheses : false
#多行声明语句按照=对齐
#AlignConsecutiveDeclarations: true
#连续的赋值语句以 = 为中心对齐
AlignConsecutiveAssignments: true
#等号两边的空格
SpaceBeforeAssignmentOperators: true
# 容器类的空格 例如 OC的字典
#SpacesInContainerLiterals: true
#缩进
#IndentWrappedFunctionNames: true
BreakConstructorInitializersBeforeComma: false
AlwaysBreakBeforeMultilineStrings: false
#BAS_AlwaysBreak : false
#BreakBeforeBraces: Allman
BreakBeforeBraces: Allman
BreakConstructorInitializersBeforeComma: false
AlwaysBreakBeforeMultilineStrings: false
AlignAfterOpenBracket: Align
#在block从空行开始
#KeepEmptyLinesAtTheStartOfBlocks: true
#在构造函数初始化时按逗号断行,并以冒号对齐
#BreakConstructorInitializersBeforeComma: true
#函数参数换行
AllowAllParametersOfDeclarationOnNextLine: true
#括号后添加空格
#SpaceAfterCStyleCast: true
#tab键盘的宽度
TabWidth: 4
UseTab: Never
AllowShortFunctionsOnASingleLine: None
ColumnLimit: 200

转自

https://biggates.github.io/2018/05/22/git-clang-format-integration.html

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值