vs code C++ 代码格式化

摘要:
简介vscode没有vs输入就格式化但是也很方面右键点击FormatDocument格式化。代码就很漂亮了。其实还是推荐自动化保存C++https://www.cnblogs.com/x_wukong/p/12643095.htmlclang-format如果失效参考链接https://github.com/microsoft/vscode-cpptools/issues/3174#issuecomment-463944461如果依旧失败推荐最后暴力一击参考链接https://www.cnblogs.com/liuyunbin/p/11538267.html个人方法不推荐,我的vscode应该是本地和云端的弄混淆了,好伤心。可以是用makefile直接写好命令生成格式文件clang-format-style=llvm-dump-config˃.clang-format里面的对应可以修改下面大致写了意思。
简介

vscode 没有 vs 输入就格式化但是 也很方面
右键点击 Format Document 格式化。 代码就很漂亮了。

其实还是推荐自动化保存C++

https://www.cnblogs.com/x_wukong/p/12643095.html
clang-format

如果失效

参考链接 https://github.com/microsoft/vscode-cpptools/issues/3174#issuecomment-463944461

如果依旧失败

推荐最后暴力一击
参考链接
https://www.cnblogs.com/liuyunbin/p/11538267.html
个人方法不推荐,我的vscode应该是本地和云端的弄混淆了,好伤心。可以是用makefile 直接写好命令
生成格式文件clang-format -style=llvm -dump-config > .clang-format
里面的对应可以修改
下面大致写了意思。大家努力。

FORMAT = clang-format -i 
...
format :
	find . -regex '.*.(cpp|hpp|cc|cxx)' -exec clang-format -style=file -i {} ;
个人的.clang-format
---
Language:        Cpp
# BasedOnStyle:  LLVM
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: false
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands:   true
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
  AfterCaseLabel:  false
  AfterClass:      false
  AfterControlStatement: false
  AfterEnum:       false
  AfterFunction:   false
  AfterNamespace:  false
  AfterObjCDeclaration: false
  AfterStruct:     false
  AfterUnion:      false
  AfterExternBlock: false
  BeforeCatch:     false
  BeforeElse:      false
  IndentBraces:    false
  SplitEmptyFunction: true
  SplitEmptyRecord: true
  SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit:     120
CommentPragmas:  '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: false
DisableFormat:   false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
  - foreach
  - Q_FOREACH
  - BOOST_FOREACH
IncludeBlocks:   Preserve
IncludeCategories:
  - Regex:           '^"(llvm|llvm-c|clang|clang-c)/'
    Priority:        2
    SortPriority:    0
  - Regex:           '^(<|"(gtest|gmock|isl|json)/)'
    Priority:        3
    SortPriority:    0
  - Regex:           '.*'
    Priority:        1
    SortPriority:    0
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentCaseLabels: false
IndentGotoLabels: true
IndentPPDirectives: None
IndentWidth:     4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd:   ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
ReflowComments:  true
SortIncludes:    true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles:  false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
Standard:        Latest
StatementMacros:
  - Q_UNUSED
  - QT_REQUIRE_VERSION
TabWidth:        8
UseCRLF:         false
UseTab:          Never
...


免责声明:文章转载自《vs code C++ 代码格式化》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇修改chrome插件ModuleNotFoundError: No module named 'numpy.testing.nosetester'----import sklearn.datasets.make_moons报错下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

上传及更新代码到github(以及如何在vscode上提交自己的代码)

  一、上传本地代码 第一步:去github上创建自己的Repository,创建页面如下图所示: 红框为新建的仓库的https地址 在git bash里输入上面图片提示要输入的命令的6句话 第二步:添加readme内容 第三步:建立git仓库 第四步:将项目的所有文件添加到仓库中 第五步:把readme添加到项目中 第六步:提交到仓库-m为添加注释...

Java代码格式化规范实践总结

目标说明 统一良好的代码格式规范可以有效提升开发团队之间的「协作效率」,如果不同的开发团队或者开发人员采用不同的代码格式规范,那么每次Format代码都会导致大量的变化,在Code Review及Merge代码时会带来很多的干扰项。因此制定本代码规范希望达成以下目标: 统一Java代码格式规范,确保团队成员间「代码风格一致」; 保证Format代码时不会...

在tc上安装buildkit.tcz,vscode.tcz,打通vscodeonline与openfaas模拟cloudbase打造碎片化编程开发部署环境

本文关键字:rebuild kernel invalid magic number,failed to create diff tar stream: failed to get xattr for : operation not supported 在《一种用buildkit打造免registry的local cd/ci工具,打通vscodeonline...

格式化响应数据

格式化响应数据 原文:Formatting Response Data作者:Steve Smith翻译:刘怡(AlexLEWIS)校对:许登洋(Seay) ASP.NET Core MVC 内建支持对相应数据(response data)的格式化,用来修正格式或生成客户端指定的格式。 从 GitHub 上查看或下载相关样例。 特定格式的操作结果 某些操作...

vscode 使用技巧

vs coder中foler和workspace区别: 官方文档说明workspace: https://code.visualstudio.com/docs/editor/multi-root-workspaces#_opening-workspace-files vscode左侧不同颜色的含义: 代码里的左侧颜色标识: 红色,未加入版本控制; (刚cl...

Manjaro 安装 &amp;amp; 配置

Manjaro 配置 记录安装Manjaro后的一些配置, 便于日后查阅和使用 目录 Manjaro 配置 安装 源 安装软件 编辑配置文件 其他配置 参考 安装 ​ 启动盘: dd if="iso镜像路径" of="目标U盘路径"(查看U盘设备名fdisk -l), 查看进度: sudo watch -n 5 killall -...