个人.clang-format配置,适合Linux C/C++
安装
在VSCode扩展里搜索clangd并安装
配置
在项目的根目录下添加.clang-format文件,配置如下:
BasedOnStyle: LLVM
Language: Cpp
# This style configuration is based on google style configuration.
# The following configuration is different from the basic configuration.
# 缩进宽度
IndentWidth: 4
# Tab宽度
TabWidth: 4
# 每行代码长度限制,0表示无限制
ColumnLimit: 0
# 大括号使用Linux代码风格
BreakBeforeBraces: Linux
# 允许函数参数在一行
AllowAllArgumentsOnNextLine: true
# 使用Tab字符,Never表示不使用
UseTab: Never
使用
格式化代码:选中要格式化的代码,鼠标右键,使用…格式化代码(Format Document With…),选择clangd。