简介

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++ 代码格式化的更多相关文章

  1. 处理code中代码格式化与eslint冲突

    在结尾去掉分号 让字符串格式化之后用单引号表示 去掉格式化后自动给末尾加的逗号 在根目录下新建一个文件prettierrc 输入如下 函数名与()之间取消空格 打开eslintrc.js 输入如下代码 ...

  2. VS Code C++ 代码格式化(clang-format)

    --- # 语言: None, Cpp, Java, JavaScript, ObjC, Proto, TableGen, TextProto Language: Cpp # BasedOnStyle ...

  3. HTML-CSS-JS Prettify 代码格式化插件

    前提:已经安装 node.js.安装插件 HTML-CSS-JS Prettify,修改node路径,即可通过单击右键 HTML-CSS-JS Prettify 中的 Prettify Code 使用 ...

  4. vscode代码格式化快捷键及保存时自动格式化

    一.实现vs code中代码格式化快捷键:[Shift]+[Alt]+ F 二.实现保存时自动代码格式化: 1)文件 ------.>[首选项]---------->[设置]: 2)搜索  ...

  5. code blocks 如何实现一键代码格式化

    问题:code blocks 如何实现一键代码格式化 解答:直接右键,选择format use ASstyle

  6. vs code中Vue代码格式化的问题

    个人网站 https://iiter.cn 程序员导航站 开业啦,欢迎各位观众姥爷赏脸参观,如有意见或建议希望能够不吝赐教! VSCode自从更新之后,vue文件的html代码格式化就失效了,而且vu ...

  7. vs Code + Eslint + Prettier 代码格式化(vue开发)

    一.什么是Eslint 通过查看eslint官网(官网传送门),我们就可以知道,eslint就是一个用来识别 ECMAScript/JavaScript 并且按照规则给出报告的代码检测工具,主要用来检 ...

  8. AndroidStudio导入Eclipse的代码格式化文件

    对于一个团队来说,使用统一的代码格式是非常重要的,否则在使用版本控制工具时,会出现大量的冲突.在Eclipse里,我们可以通过一些xml来进行代码格式的统一,但是这些文件要应用在AndroidStud ...

  9. astyle代码格式化

    Artistic Style 1.24 A Free, Fast and Small Automatic Formatterfor C, C++, C#, and Java Source Code 项 ...

  10. eclipse 代码清理 代码格式化 代码凝视

    Code Style包含两个方面:代码清理,代码规范化.代码清理能够參考: http://www.ibm.com/developerworks/cn/opensource/os-eclipse-cle ...

随机推荐

  1. eolink对数据进行四舍五入处理

    下图"BalanceAmount"返回值显示小数点2位以后的值,这样就与预计匹配值不等导致脚本错误 对这个值进行四舍五入处理,比如返回值变成整数 var num = eo.env. ...

  2. 内网穿透——Natapp实现

    转自:NATAPP使用教程(内网穿透)_Willing卡卡的博客-CSDN博客_natapp NATAPP内网穿透使用教程 本文主要分享了有关内网穿透NATAPP的使用,包括:注册.建立隧道(免费). ...

  3. 关于Bevy中的原型Archetypes

    认识Bevy中的原型 Bevy是基于ECS(Entity-Component-System)架构的游戏引擎,其中的Entity实体是游戏中的一个基本对象,但实体本身通常只是一个标识id,它不包含任何具 ...

  4. python-docx 设置表格边框

    # -*- coding: utf-8 -*- """ Created on Sat Oct 24 17:21:31 2020 pip install -i https: ...

  5. Gin RBAC 权限基础实现

    RBAC (基于角色的访问控制) 是一种广泛应用的权限管理模型, 通过 角色 将 用户 和 权限 解耦, 简化权限分配管理. 用户 (User): 系统的使用者 权限 (Permission): 对资 ...

  6. 【语义分割专栏】先导篇:评价指标(PA,CPA,IoU,mIoU,FWIoU,F1)

    目录 前言 混淆矩阵 计算混淆矩阵 评价指标 像素准确率(Pixel Accuracy,PA) 类别像素准确率(Class Pixel Accuracy,CPA) 类别平均像素准确率(Mean Pix ...

  7. ASP.NET Core已有数据库,却新建项目

    ASP.NET Core已有数据库,却新建项目,只需要构造出相应的类,DbContext,然后直接add-migration init即可!!而不用执行update-database,执行后者会报错: ...

  8. Spring AOP 面向切面编程之搞定表单重复提交实战

    摘要:客户端在5秒内请求同一URL,而且关键请求参数相等,则视此次请求为重复提交,利用自定义注解 .Spring AOP 和 Guava Cache 技术栈在服务器端实现拦截表单重复提交,防止刷单. ...

  9. docker部署mysql5.7后登录时出现Access denied for user 'root'@'localhost' (using password: YES)的解决方法

    1.先进去容器中安装vim工具 docker exec -it mysql bash apt-get update apt-get -y install vim 2.修改/etc/mysql/conf ...

  10. linux系统qcow2镜像的制作

    一.简单说明 PS: 最近有客户需要在云平台上部署我们的产品,好久没有做过qcow2镜像了,这里还是把制作流程记录下来. QCOW2镜像格式是Qemu支持的磁盘镜像格式之一.它可以使用一个文件来表示一 ...