栏目分类:
子分类:
返回
终身学习网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
终身学习网 > IT > 软件开发 > 后端开发 > C/C++/C#

linux vim(nvim)c++代码格式化工具clang-format

C/C++/C# 更新时间:发布时间: 百科书网 趣学号
  1. 安装vim-clang-format插件
    项目地址:vim-clang-format
    如果用Plug管理vim插件,直接在.vimrc中添加一行
    Plug ‘rhysd/vim-clang-format’
    运行:PlugInstall就可以自动安装插件

  2. 配置
    支持的语言
    C
    C++
    Objective-C
    JavaScript
    java
    TypeScript
    Protobuf

" map to cf in C++ code
autocmd FileType h,cc,c,cpp,objc nnoremap cf :ClangFormat
autocmd FileType h,cc,c,cpp,objc vnoremap cf :ClangFormat
" let g:clang_format#auto_format_on_insert_leave=1	"退出插入模式时自动格式化
  1. 安装clang-format:
    npm install -g clang-format
  2. 格式化方式
    可以创建一个文件.clang-format放到根目录
    可以参考: https://www.cnblogs.com/lepeCoder/p/8032178.html
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
# To disable for a line use `// clang-format off`
# IndentPPDirectives: BeforeHash

#WebKit:符合WebKit的样式指南的样式
AccessModifierOffset: -1
ConstructorInitializerIndentWidth: 4
AlignEscapedNewlinesLeft: true
AllowShortLoopsOnASingleLine: true
AlwaysBreakTemplateDeclarations: true
AlwaysBreakBeforeMultilineStrings: true
BreakBeforeBinaryOperators: false
BreakBeforeTernaryOperators: true
BinPackParameters: true
ConstructorInitializerAllOnOneLineOrOnePerLine: true
DerivePointerBinding: true
ExperimentalAutoDetectBinPacking: false
IndentCaseLabels: true
NamespaceIndentation: None
ObjCSpaceBeforeProtocolList: false
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 60
PenaltyBreakString: 1000
PenaltyBreakFirstLessLess: 120
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerBindsToType: true
SpacesBeforeTrailingComments: 2
Cpp11BracedListStyle: true
Standard:        Auto
BreakBeforeBraces: Attach
IndentFunctionDeclarationAfterType: true
SpacesInAngles:  false
SpaceInEmptyParentheses: false
SpacesInCStyleCastParentheses: false
SpaceAfterControlStatementKeyword: true
ContinuationIndentWidth: 4


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


大功告成

转载请注明:文章转载自 www.051e.com
本文地址:http://www.051e.com/it/1034293.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 ©2023-2025 051e.com

ICP备案号:京ICP备12030808号