Linux系统配置Vscode中clang-format代码格式化配置

安装
在VSCode扩展里搜索clang-format安装
在这里插入图片描述

Linux系统安装:使用命令

sudo apt install clang-format

安装后,查找安装的地址:

which clang-format

生成.clang-format配置文件并修改
生成.clang-format配置文件命令:

clang-format --style=LLVM --dump-config > ./.clang-format

如下基于LLVM风格进行的定制:

---
BasedOnStyle:   LLVM
Language:        Cpp

# this style configuration is based on google style configuration.
# The following configuration is different from the basic configuration.

# 缩进宽度
IndentWidth:     4

# 访问权限说明符(public/private)的偏移
AccessModifierOffset: -4

# # 开括号(开圆括号、尖括号、方括号)后的对齐: Align, DontAlign, AlwaysBreak(总是在开括号后换行)
# AlignAfterOpenBracket: Align

# # 连续赋值时,对齐所有等号
AlignConsecutiveAssignments: true

# # 连续声明时,对齐所有声明的变量名
AlignConsecutiveDeclarations: true

# 反斜杆换行的对齐方式
# -- DontAlign - 不进行对齐
# -- Left - 反斜杠靠左对齐
# -- Right - 反斜杠靠右对齐
# AlignEscapedNewlines: Right

# 二元、三元表达式的对齐方式(当表达式需要占用多行时)
# -- DontAlign - 不进行对齐
# -- Align - 从操作符开始对齐
# -- AlignAfterOperator - 从操作数开始对齐
AlignOperands:   true

# # 是否对齐行尾注释
AlignTrailingComments: true

# # 函数声明的所有参数在放在下一行
# AllowAllParametersOfDeclarationOnNextLine: false

# # 是否允许短的代码块放在同一行
# AllowShortBlocksOnASingleLine: false

# # 短的case标签和语句放在同一行
# AllowShortCaseLabelsOnASingleLine: true

# # 短的函数放在同一行
# -- None - 不把短的函数放在同一行
# -- InlineOnly - 只把类内的内联函数放在同一行,全局的空函数不放在同一行
# -- Empty - 只把空的函数放在同一行
# -- Inline - 把类内的内联函数放在同一行,全局的空函数不放在同一行
# -- All - 都允许放在同一行
AllowShortFunctionsOnASingleLine: InlineOnly

# # 短的if语句保持在同一行
# AllowShortIfStatementsOnASingleLine: true

# # 短的循环保持在同一行
# AllowShortLoopsOnASingleLine: true

# # 总是在返回类型后换行: None, All, TopLevel(顶级函数,不包括在类中的函数), 
# # AllDefinitions(所有的定义,不包括声明), TopLevelDefinitions(所有的顶级函数的定义)
# AlwaysBreakAfterReturnType: None

# # 总是在多行string字面量前换行
# AlwaysBreakBeforeMultilineStrings: true

# # 总是在template声明后换行
AlwaysBreakTemplateDeclarations: true

# # 函数调用时,参数的放置规则
# -- false - 参数要么放在同一行,要么每个参数占用一行
# -- 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值