【VS】visual studio 代码格式化工具--clang-format

这篇具有很好参考价值的文章主要介绍了【VS】visual studio 代码格式化工具--clang-format。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

【VS】visual studio 代码格式化工具–clang-format

1.到visual studio的tools->Extensions and updates

【VS】visual studio 代码格式化工具--clang-format

2.在Extensions and updates查找clangFormat 插件

【VS】visual studio 代码格式化工具--clang-format

3.安装完插件,重启vs,菜单中会多出两个菜单:

【VS】visual studio 代码格式化工具--clang-format
分别表示格式化选中代码与格式化文档。、

虽然现在的🆚022 已经内置了,但是大部分的流程都是一样的
【VS】visual studio 代码格式化工具--clang-format

4.到AppData\Local\Microsoft\VisualStudio\14.0\Extensions\2d20hrwn.tkx目录找到clang-format.exe,并在cmd上输入:.\clang-format.exe -style="Google" -dump-config > .clang-format

【VS】visual studio 代码格式化工具--clang-format
就生成了.clang-format文件:

【VS】visual studio 代码格式化工具--clang-format

5.将这个文件拷贝到需要格式化代码的文件夹中,就可以用这个插件功能了。

附.clang-format文件:文章来源地址https://www.toymoban.com/news/detail-507786.html

---
Language:        Cpp
BasedOnStyle:  Google
AccessModifierOffset: -1
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: None
AlignConsecutiveAssignments: None
AlignConsecutiveBitFields: None
AlignConsecutiveDeclarations: None
AlignEscapedNewlines: Left
AlignOperands:   Align
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortEnumsOnASingleLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: WithoutElse
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
AttributeMacros:
  - __capability
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
  AfterCaseLabel:  false
  AfterClass:      false
  AfterControlStatement: Never
  AfterEnum:       false
  AfterFunction:   false
  AfterNamespace:  false
  AfterObjCDeclaration: false
  AfterStruct:     false
  AfterUnion:      false
  AfterExternBlock: false
  BeforeCatch:     false
  BeforeElse:      false
  BeforeLambdaBody: false
  BeforeWhile:     false
  IndentBraces:    false
  SplitEmptyFunction: true
  SplitEmptyRecord: true
  SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: true
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: true
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit:     100
#CommentPragmas:  '^ IWYU pragma:'
#CommentPragmas:  '^[^ ]'
CommentPragmas:  '^\\.+'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: true
DisableFormat:   false
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
  - foreach
  - Q_FOREACH
  - BOOST_FOREACH
StatementAttributeLikeMacros:
  - Q_EMIT
IncludeBlocks:   Preserve
IncludeCategories:
  - Regex:           '^<ext/.*\.h>'
    Priority:        2
    SortPriority:    0
    CaseSensitive:   false
  - Regex:           '^<.*\.h>'
    Priority:        1
    SortPriority:    0
    CaseSensitive:   false
  - Regex:           '^<.*'
    Priority:        2
    SortPriority:    0
    CaseSensitive:   false
  - Regex:           '.*'
    Priority:        3
    SortPriority:    0
    CaseSensitive:   false
IncludeIsMainRegex: '([-_](test|unittest))?$'
IncludeIsMainSourceRegex: ''
IndentCaseLabels: true
IndentCaseBlocks: false
IndentGotoLabels: true
IndentPPDirectives: None
IndentExternBlock: AfterExternBlock
IndentRequires:  false
IndentWidth:     2
IndentWrappedFunctionNames: false
InsertTrailingCommas: None
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd:   ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Never
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PenaltyIndentedWhitespace: 0
PointerAlignment: Left
RawStringFormats:
  - Language:        Cpp
    Delimiters:
      - cc
      - CC
      - cpp
      - Cpp
      - CPP
      - 'c++'
      - 'C++'
    CanonicalDelimiter: ''
    BasedOnStyle:    google
  - Language:        TextProto
    Delimiters:
      - pb
      - PB
      - proto
      - PROTO
    EnclosingFunctions:
      - EqualsProto
      - EquivToProto
      - PARSE_PARTIAL_TEXT_PROTO
      - PARSE_TEST_PROTO
      - PARSE_TEXT_PROTO
      - ParseTextOrDie
      - ParseTextProtoOrDie
      - ParseTestProto
      - ParsePartialTestProto
    CanonicalDelimiter: ''
    BasedOnStyle:    google
ReflowComments:  true
SortIncludes:    true
SortJavaStaticImport: Before
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceAroundPointerQualifiers: Default
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles:  true
SpacesInConditionalStatement: false
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
BitFieldColonSpacing: Both
Standard:        Auto
StatementMacros:
  - Q_UNUSED
  - QT_REQUIRE_VERSION
TabWidth:        8
UseCRLF:         false
UseTab:          Never
WhitespaceSensitiveMacros:
  - STRINGIZE
  - PP_STRINGIZE
  - BOOST_PP_STRINGIZE
  - NS_SWIFT_NAME
  - CF_SWIFT_NAME
...
 

到了这里,关于【VS】visual studio 代码格式化工具--clang-format的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • VS Code保存后自动格式化Vue代码---Vetur

    在VS Code里面编辑Vue代码,通常我们会安装插件Vetur,本次介绍的格式化代码也依赖于Vetur插件。具体见一下步骤 注: VS Code版本为1.74.3 1. 安装插件Vetur 2. 配置自动格式化,具体路径【文件】-【首选项】-【设置】,打开设置(json) 3. 将以下内容复制到settings.json 完成以上配置

    2024年02月15日
    浏览(40)
  • IDEA代码自动格式化工具

    在IDEA中,打开 IDEA 的设置,找到 Editor - General - Auto Import。勾选上 Add unambiguous imports on the fly Optimize imports on the fly (for current project) 设置方法如下: 1.打开设置 2.找到版本控制(Version Control),点击提交(Commit) 3.勾选Before Commit下的Reform code activate save actions on save – 在保存的时候激活

    2024年02月15日
    浏览(44)
  • VS Code 一键删除所有注释,仨健格式化全部代码,一键去除行尾空格空白

    1. 打开VSCode的替换页面,快捷键为: Ctl + H 2. 鼠标左击使能正则表达式选项,快捷键为: Alt + R 3. 瞄准全部注释的正则表达式为:       4. 替换的内容什么都不写, 鼠标左击替换全部, 快捷键为: Ctl + Alt + Enter 5. 如果想删除全部空行,瞄准全部空行的正则表达式为: 同样用空来替换全

    2024年02月03日
    浏览(38)
  • Python 代码格式化工具YAPF 0.17.0问世

    导读 YAPF 0.17.0 已发布,YAPF 是 Google 开源的一个用来格式化 Python 代码的工具。 目前用于 Python 的格式化程序(如 autopep8 和 pep8ify)都用于删除代码中的 lint 错误。这有很明显的局限性。YAPF 采用了不同的方法,基于 Daniel Jasper 开发的 “clang-format” 。从本质上来说,该算法取

    2024年02月05日
    浏览(57)
  • Python 潮流周刊#25:性能最快的代码格式化工具 Ruff!

    你好,我是猫哥。这里每周分享优质的 Python、AI 及通用技术内容,大部分为英文。标题取自其中一则分享,不代表全部内容都是该主题,特此声明。 本周刊由 Python猫 出品,精心筛选国内外的 250+ 信息源,为你挑选最值得分享的文章、教程、开源项目、软件工具、播客和视频

    2024年02月06日
    浏览(51)
  • VSCode 配置 python 代码格式化工具(yapf,autopep8)

    需要注意的是,yapf的配置选项都是可选的,你可以根据自己的需要选择使用哪些选项。不过,使用太多选项可能会导致代码格式化的规则变得复杂,对代码的可读性有影响。因此,建议尽量使用最少的选项来保持代码的简洁性。 aggressive: 这个选项表示在格式化代码时使用更

    2024年02月09日
    浏览(54)
  • Python 进阶指南(编程轻松进阶):三、使用 Black 工具来格式化代码

    原文:http://inventwithpython.com/beyond/chapter3.html 代码格式化是将一组规则应用于源代码,从而使得代码风格能够简洁统一。虽然代码格式对解析程序的计算机来说不重要,但代码格式对于可读性是至关重要的,这是维护代码所必需的条件。如果你的代码对人(无论是你还是同事)

    2023年04月09日
    浏览(63)
  • 【工具分享】程序员在线工具集(json格式化-html格式化-加密工具)

    演示地址 在线工具集 功能介绍 json格式化 。 JSON 可以将程序语言对象中表示的一组数据转换为字符串,然后就可以在网络或者程序之间轻松地传递这个字符串,并在需要的时候将它还原为各编程语言所支持的数据格式,例如在 PHP 中,可以将 JSON还原为数组或者一个基本对象

    2024年02月12日
    浏览(35)
  • vscode中怎样格式化js代码_vscode如何格式化代码

    vs code格式化代码的快捷键如下: 在Mac上 Shift+ Option+F 在Ubuntu上 Ctrl+ Shift+I 但是自带的格式化并不能满足我的需求,这个时候,不得不说插件大法好。 代码格式化为eslint风格 需要插件:eslint

    2024年02月16日
    浏览(51)
  • JSON格式化工具

    格式化JSON有多种方式,选两种。 我喜欢用这个网站:在线JSON工具 需要插件 - JSON Viewer。 安装方式: 2.1 点击工具栏“插件”-选择“插件管理…”,弹出插件管理窗口,在“可用”tab页,找到“JSON viewer ”,勾选,点击右上方的“安装”按钮,等待一会,就可以了。 2.2 如果因

    2024年02月05日
    浏览(57)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包