vscode使用clang-format格式化C++代码

1.安装c/c++插件

2.在首选项-》设置中搜索format,设置Editor: Default Formatter为ms-vscode.cpptools

3.在扩展C/C++中设置

“Clang_format_path”:"C:\\Users\\user\\.vscode\\extensions\\ms-vscode.cpptools-1.0.1\\LLVM\\bin\\clang-format"

C_Cpp: Clang_format_style:“Google”

C_Cpp: Clang_format_fallback Style:“Google”

4.使用快捷键ctrl+alt+F格式化代码。

 

#Ubuntu

 

0.install xaiver-clang-format插件 

1.sudo apt install clang-format

2.首选项-》设置中搜索format,设置Editor: Default Formatter 为xaiver-clang-format

3.设置Assume Filename 和Executable

4.Ctrl + Shift + I

.clangformat文件

# 基于那个配置文件
BasedOnStyle: LLVM
# 访问说明符的偏移(public private)
AccessModifierOffset: -4
# 括号之后,水平对齐参数: Align DontAlign AlwaysBreak
AlignAfterOpenBracket: Align
# 连续的赋值时,对齐所有的等号
AlignConsecutiveAssignments: true
# 连续声明时,对齐所有声明的变量名
AlignConsecutiveDeclarations: true
# 左对齐换行(使用反斜杠换行)的反斜杠 
AlignEscapedNewlinesLeft: true
# 水平对齐二元和三元表达式的操作数 
AlignOperands: true
# 对齐连续的尾随的注释  
AlignTrailingComments: true
# 允许函数声明的所有参数在放在下一行  
AllowAllParametersOfDeclarationOnNextLine: true
# 允许短的块放在同一行  
AllowShortBlocksOnASingleLine : false
# 允许短的case标签放在同一行
AllowShortCaseLabelsOnASingleLine: false
# 允许短的函数放在同一行: None, InlineOnly(定义在类中), Empty(空函数), Inline(定义在类中,空函数), All 
AllowShortFunctionsOnASingleLine: Empty
# 是否允许短if单行 If true, if (a) return; 可以放到同一行
AllowShortIfStatementsOnASingleLine: false
# 允许短的循环保持在同一行   
AllowShortLoopsOnASingleLine: false 
# 总是在定义返回类型后换行(deprecated)   
AlwaysBreakAfterDefinitionReturnType: None
# 每行字符的限制,0表示没有限制  
ColumnLimit: 100
# 描述具有特殊意义的注释的正则表达式,它不应该被分割为多行或以其它方式改变
CommentPragmas: '^ IWYU pragma:'
# 语言: None Cpp Java Objc Protp
Language: Cpp 
#指针的*的挨着哪边
PointerAlignment: Right
#缩进宽度
IndentWidth: 4
# 连续的空行保留几行
MaxEmptyLinesToKeep: 1
# 在 @property 后面添加空格, \@property (readonly) 而不是 \@property(readonly).
ObjCSpaceAfterProperty: true
# OC block后面的缩进
ObjCBlockIndentWidth: 4
# 是否允许短方法单行
AllowShortFunctionsOnASingleLine: false
# 换行的时候对齐操作符
#AlignOperands: true
# 中括号两边空格 [] 
SpacesInSquareBrackets: true
# 小括号两边添加空格
SpacesInParentheses : false
#等号两边的空格
SpaceBeforeAssignmentOperators: true
# 容器类的空格 例如 OC的字典
SpacesInContainerLiterals: true
#缩进
IndentWrappedFunctionNames: true
#在block从空行开始
KeepEmptyLinesAtTheStartOfBlocks: true
#在构造函数初始化时按逗号断行,并以冒号对齐
BreakConstructorInitializersBeforeComma: true
#括号后添加空格
SpaceAfterCStyleCast: false
# 允许排序#include, 造成编译错误
# SortIncludes: true 
# 缩进case 标签
IndentCaseLabels: true 
#tab键盘的宽度
TabWidth: 4
UseTab: Never

 

 

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值