vs code C++ 代码格式化
简介
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++ 代码格式化的更多相关文章
- 处理code中代码格式化与eslint冲突
在结尾去掉分号 让字符串格式化之后用单引号表示 去掉格式化后自动给末尾加的逗号 在根目录下新建一个文件prettierrc 输入如下 函数名与()之间取消空格 打开eslintrc.js 输入如下代码 ...
- VS Code C++ 代码格式化(clang-format)
--- # 语言: None, Cpp, Java, JavaScript, ObjC, Proto, TableGen, TextProto Language: Cpp # BasedOnStyle ...
- HTML-CSS-JS Prettify 代码格式化插件
前提:已经安装 node.js.安装插件 HTML-CSS-JS Prettify,修改node路径,即可通过单击右键 HTML-CSS-JS Prettify 中的 Prettify Code 使用 ...
- vscode代码格式化快捷键及保存时自动格式化
一.实现vs code中代码格式化快捷键:[Shift]+[Alt]+ F 二.实现保存时自动代码格式化: 1)文件 ------.>[首选项]---------->[设置]: 2)搜索 ...
- code blocks 如何实现一键代码格式化
问题:code blocks 如何实现一键代码格式化 解答:直接右键,选择format use ASstyle
- vs code中Vue代码格式化的问题
个人网站 https://iiter.cn 程序员导航站 开业啦,欢迎各位观众姥爷赏脸参观,如有意见或建议希望能够不吝赐教! VSCode自从更新之后,vue文件的html代码格式化就失效了,而且vu ...
- vs Code + Eslint + Prettier 代码格式化(vue开发)
一.什么是Eslint 通过查看eslint官网(官网传送门),我们就可以知道,eslint就是一个用来识别 ECMAScript/JavaScript 并且按照规则给出报告的代码检测工具,主要用来检 ...
- AndroidStudio导入Eclipse的代码格式化文件
对于一个团队来说,使用统一的代码格式是非常重要的,否则在使用版本控制工具时,会出现大量的冲突.在Eclipse里,我们可以通过一些xml来进行代码格式的统一,但是这些文件要应用在AndroidStud ...
- astyle代码格式化
Artistic Style 1.24 A Free, Fast and Small Automatic Formatterfor C, C++, C#, and Java Source Code 项 ...
- eclipse 代码清理 代码格式化 代码凝视
Code Style包含两个方面:代码清理,代码规范化.代码清理能够參考: http://www.ibm.com/developerworks/cn/opensource/os-eclipse-cle ...
随机推荐
- Cursor+playwright+mcp,好玩
Cursor+playwright+mcp能干嘛,我就不多说,本文只讲怎么用上 第一步,安装下载Cursor.node.js,至于什么python环境,playwright网上一堆教程,自己查 第二步 ...
- MySQL 的覆盖索引是什么?
MySQL 的覆盖索引是什么? 覆盖索引(Covering Index)是指索引本身包含了查询所需的所有字段数据,从而无需再回表查询的数据访问方式.这种优化能够显著提升查询性能. 1. 覆盖索引的特点 ...
- Java高效合并Excel报表实战:GcExcel让数据处理更简单
前言:为什么需要自动化合并Excel? 在日常办公场景中,Excel报表合并是数据分析的基础操作.根据2023年企业办公效率报告显示: 财务人员平均每周花费6.2小时在Excel合并操作上 人工合并的 ...
- 【深度思考】自定义日期格式,为什么@JSONField生效,@JsonFormat不生效?
1. 前言 最近在自测接口时,发现一个问题:字段类型定义的是Date,但接口返回值里却是时间戳(1744959978674), 而不是预期的2025-04-18 15:06:18. private D ...
- 一步到位js/javascript对象和querystring查询字符串互转(get/url参数)
当然,这个问题又很多解决方式,这里说一种最简洁的方式: 对象转querystring查询字符串(get/url参数) 我看网上的方法都比较繁琐,其实可以直接使用js的URLSearchParams对象 ...
- 11.7K Star!这个分布式爬虫管理平台让多语言协作如此简单!
嗨,大家好,我是小华同学,关注我们获得"最新.最全.最优质"开源项目和高效工作学习方法 分布式爬虫管理平台Crawlab,支持任何编程语言和框架的爬虫管理,提供可视化界面.任务调度 ...
- Asp.net core中HttpResponse常用属性及Status code
在ASP.NET Core中,HttpResponse 表示HTTP响应,其中包括一些常用的属性和方法,用于设置HTTP响应的各种属性.HTTP响应通常由一个HTTP状态码,HTTP头(headers ...
- ASP.NET Core之由配置系统与创建app所想到的
先看文件配置的代码: ConfigurationBuilder configBuilder=new ConfigurationBuiler();//典型的创建者模式 configBuilder.Add ...
- elasticsearch RestHighLevelClient 关于document的常用操作 ---------- 编辑篇
es中的编辑分为:基于id的单条件编辑.自定义条件的编辑 基于id的单条件编辑:UpdateRequest 基于自定义条件的编辑:需借助底层脚本语言来实现有高低版本区分(见文章尾部)更新于2021-0 ...
- 「Note」您想来点数据结构吗?
大分块系列 最初分块 \(\color{black}{P4119}\) 考虑数列分块+值域分块 数列分块需要维护: \(nid_{i,j}\) \(fid_i\) \(f_i\) 块 \(i\) 中数 ...