Visual Studio的默认工作.clang格式文件 我想在VisualStudio 2019(不是代码)中使用CLANC++语法,稍作修改。我创建了一个.clang格式的文件,并将其复制到我的项目中。Visual Studio可以识别该文件,但会提示我大量无法识别的密钥(例如

Visual Studio的默认工作.clang格式文件 我想在VisualStudio 2019(不是代码)中使用CLANC++语法,稍作修改。我创建了一个.clang格式的文件,并将其复制到我的项目中。Visual Studio可以识别该文件,但会提示我大量无法识别的密钥(例如,c++,visual-studio,clang-format,C++,Visual Studio,Clang Format,YAML:87:19:错误:未知键“IndentCaseBlocks” )。对于Visual Studio,是否有一个推荐的默认文件,其中包含表示标准格式的最大支持(或可能推荐)设置数 编辑:当我编辑.clang格式文件时,某些键确实起作用,例如TabIndent或ColumnLimit。我的版本是VS 16.8.4。您的clang文件的内容似乎有一些问题。您可以访问clang的官方网站了解更多信息 首先,您需要检查Tools->Options->Text Editor->C/C++->Form

YAML:87:19:错误:未知键“IndentCaseBlocks”

)。对于Visual Studio,是否有一个推荐的默认文件,其中包含表示标准格式的最大支持(或可能推荐)设置数


编辑:当我编辑
.clang格式
文件时,某些键确实起作用,例如
TabIndent
ColumnLimit
。我的版本是VS 16.8.4。

您的clang文件的内容似乎有一些问题。您可以访问clang的官方网站了解更多信息

首先,您需要检查
Tools->Options->Text Editor->C/C++->Formatting->General->Enable ClangFormat support
。您也可以
使用自定义的clang-format.exe文件

然后,您可以右键单击项目,添加一个新项目,然后选择
格式化->叮当格式文件
。所以你可以在里面添加你想要的东西

以下是一个参考配置文件:

BasedOnStyle: Google
Language: Cpp
ColumnLimit: 120

BraceWrapping:
 # class definition behind
 AfterClass: false
 # After the control statement
 AfterControlStatement: false
 # enum definition behind
 AfterEnum: true
 # After the function definition
 AfterFunction: false
 # After the namespace definition
 AfterNamespace: false
 # ObjC definition behind
 AfterObjCDeclaration: false
 # struct definition behind
 AfterStruct: false
 # union definition
 AfterUnion: false
 #ExternBlock definition behind
 AfterExternBlock: false
 # before catch
 BeforeCatch: false
 # else before
 BeforeElse: false
 # Indented braces
 IndentBraces: false
 # Split empty function
 SplitEmptyFunction: true
 # Split empty records
 SplitEmptyRecord: true
 # Split empty namespace
 SplitEmptyNamespace: true

# Add a space after @property, \@property (readonly) instead of \@property(readonly).
ObjCSpaceAfterProperty: true
# Offset of access specifiers (public, private, etc.)
AccessModifierOffset: -4
# Alignment after opening brackets (opening parentheses, opening angle brackets, opening square brackets): Align, DontAlign, AlwaysBreak (always wrap after opening brackets)
AlignAfterOpenBracket: Align
# When assigning consecutively, align all equal signs
AlignConsecutiveAssignments: false
# When consecutive declarations, align all declared variable names
AlignConsecutiveDeclarations: false
# Left align backslashes that escape newlines (use backslashes for newlines)
AlignEscapedNewlinesLeft: true
# Align the operands of binary and ternary expressions horizontally
AlignOperands: true
# Align consecutive trailing comments
AlignTrailingComments: true
# Allow all parameters of the function declaration to be placed on the next line
AllowAllParametersOfDeclarationOnNextLine: true
# Allow short blocks on the same line
AllowShortBlocksOnASingleLine: false
# Allow short case labels on the same line
AllowShortCaseLabelsOnASingleLine: false
# Allow short functions to be placed on the same line: None, InlineOnly (defined in the class), Empty (empty function), Inline (defined in the class, empty function), All
AllowShortFunctionsOnASingleLine: None
# Allow short if statements to stay on the same line
AllowShortIfStatementsOnASingleLine: false
# Allow short loops to stay on the same line
AllowShortLoopsOnASingleLine: false
# Always break after defining the return type (deprecated)
AlwaysBreakAfterDefinitionReturnType: None
# Always wrap after the return type: None, All, TopLevel (top functions, functions not included in the class),
# AllDefinitions (all definitions, excluding declarations), TopLevelDefinitions (the definitions of all top-level functions)
AlwaysBreakAfterReturnType: None
# Always wrap before multi-line string literal
AlwaysBreakBeforeMultilineStrings: false
# Always wrap after the template statement
AlwaysBreakTemplateDeclarations: false
# false means that the function arguments are either on the same line or on their own line
BinPackArguments: true
# false means that all formal parameters are either on the same line or on their own line
BinPackParameters: true
# Braces wrap, only valid when BreakBeforeBraces is set to Custom
# Newline before binary operators: None (newline after the operator), NonAssignment (newline before the non-assignment operator), All (newline before the operator)
BreakBeforeBinaryOperators: NonAssignment
# Wrap a line before the brace: Attach (always attach the brace to the surrounding context), Linux (except for functions, namespaces and class definitions, similar to Attach),
# Mozilla (except enumeration, function, record definition, similar to Attach), Stroustrup (except function definition, catch, else, similar to Attach),
# Allman (always break before the curly brace), GNU (always break before the curly brace, and add extra indentation to the curly brace of the control statement), WebKit (newline before the function), Custom
# Note: It is considered that the statement block also belongs to the function
BreakBeforeBraces: Custom
# Break before ternary operator
BreakBeforeTernaryOperators: true
# Break before the comma in the initialization list of the constructor
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
# Describe the regular expression of the comment with special meaning, it should not be divided into multiple lines or changed in other ways
CommentPragmas:'^ IWYU pragma:'
# The initialization list of the constructor is either all on the same line or on their own line
ConstructorInitializerAllOnOneLineOrOnePerLine: true
# The comfort list of constructors all wrap
AllowAllConstructorInitializersOnNextLine: false
# The indentation width of the initialization list of the constructor
ConstructorInitializerIndentWidth: 4
# The indentation width of the continued line
ContinuationIndentWidth: 4
# Remove the space before the curly braces {after and before the C++11 list initialization
Cpp11BracedListStyle: true
# Inherit the most commonly used pointer and reference alignment
DerivePointerAlignment: false
# Turn off formatting
DisableFormat: false
# Automatically detect whether the function call and definition are formatted as one parameter per line (Experimental)
ExperimentalAutoDetectBinPacking: false
# Fix namespace comment
FixNamespaceComments: true
# Need to be interpreted as a foreach loop instead of a function call macro
ForEachMacros:
 -foreach
 -Q_FOREACH
 -BOOST_FOREACH
# Sort #include, #include that matches a regular expression has a corresponding priority, and the default priority is INT_MAX (the smaller the priority, the higher the priority),
# You can define a negative priority to ensure that certain #include is always at the top
IncludeCategories:
 -Regex:'^<ext/.*\.h>'
   Priority: 2
 -Regex:'^<.*\.h>'
   Priority: 1
 -Regex:'^<.*'
   Priority: 2
 -Regex:'.*'
   Priority: 3

IncludeIsMainRegex:'([-_](test|unittest))?$'
# Indent case label
IndentCaseLabels: true
# Indentation width
IndentWidth: 4
# When the function return type wraps, indent the function declaration or the function name of the function definition
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
# Keep the blank line at the beginning of the block
KeepEmptyLinesAtTheStartOfBlocks: true
# The regular expression of a macro to start a block
MacroBlockBegin:''
# End the regular expression of a block macro
MacroBlockEnd:''
# Maximum number of consecutive blank lines
MaxEmptyLinesToKeep: 1
# Namespace indentation: None, Inner (indent the content in the nested namespace), All
NamespaceIndentation: None
# Indent width when using ObjC block
ObjCBlockIndentWidth: 4
# Add a space before ObjC's protocol list
ObjCSpaceBeforeProtocolList: false
# Penalty that wraps the function call after call(
PenaltyBreakBeforeFirstCallParameter: 19
# Introduce a penalty for line breaks in a comment
PenaltyBreakComment: 300
# The penalty for the first line break before <<
PenaltyBreakFirstLessLess: 120
# Introduce a penalty for line breaks in a string literal
PenaltyBreakString: 1000
# Penalty for each character outside the line character limit
PenaltyExcessCharacter: 1000000
# Put the return type of the function in the penalty of its own line
PenaltyReturnTypeOnItsOwnLine: 60
# Alignment of pointer and reference: Left, Right, Middle
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
   CanonicalDelimiter:''
   BasedOnStyle: google
# Allow retypesetting comments
ReflowComments: true
# Allow sorting#include
SortIncludes: true
SortUsingDeclarations: true
# Add space after C style type conversion
SpaceAfterCStyleCast: false
# Add a space before the assignment operator
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
# Add a space before opening the parentheses: Never, ControlStatements, Always
SpaceBeforeParens: ControlStatements
# Add spaces in empty parentheses
SpaceInEmptyParentheses: false
# The number of spaces added before trailing comments (only applicable to //)
SpacesBeforeTrailingComments: 2
# Add spaces before and after the angle brackets
SpacesInAngles: false
# Add spaces in the literal of the container (ObjC and JavaScript arrays and dictionaries, etc.)
SpacesInContainerLiterals: true
# Add spaces in the brackets of C-style type conversion
SpacesInCStyleCastParentheses: false
# Add a space before the (after and) of the parentheses
SpacesInParentheses: false
# Add a space before the [after and] of the square brackets, the declaration of lamda expressions and arrays of unspecified size will not be affected
SpacesInSquareBrackets: false
# Standard: Cpp03, Cpp11, Auto
Standard: Cpp11
# tab width
TabWidth: 4
# Use tab characters: Never, ForIndentation, ForContinuationAndIndentation, Always
UseTab: Never
BasedOnStyle:Google
语言:Cpp
限额:120
大括号包装:
#背后的类定义
课后:假
#在控制语句之后
AfterControlStatement:错误
#后面的枚举定义
AfterEnum:正确
#函数定义之后
后功能:false
#在名称空间定义之后
AfterNamespace:false
#背后的ObjC定义
声明:false
#背后的结构定义
战后:假
#联合定义
联合后:假
#后面的外部块定义
AfterExternBlock:错误
#捕获前
捕获前:错误
#以前的其他
在其他之前:错误
#缩进大括号
大括号缩进:false
#分割空函数
SplitEmptyFunction:true
#拆分空记录
SplitEmptyRecord:正确
#拆分空命名空间
SplitEmptyNamespace:true
#在@property后面添加空格,\@property(只读)而不是\@property(只读)。
ObjCSpaceAfterProperty:true
#访问说明符的偏移量(公共、私有等)
附件修改器设置:-4
#打开括号后的对齐(打开括号、打开角括号、打开方括号):对齐、DontAlign、AlwaysBreak(始终在打开括号后包裹)
AlignAfterOpen支架:对齐
#连续赋值时,对齐所有等号
对齐连续指定:false
#连续声明时,对齐所有声明的变量名
对齐连续偏差:false
#左对齐转义换行符的反斜杠(对换行符使用反斜杠)
AlignEscapedNewlinesLeft:真
#将二元和三元表达式的操作数水平对齐
对齐操作数:true
#对齐连续的尾随注释
AlignTrailingComments:正确
#允许将函数声明的所有参数放置在下一行
AllowWallParametersOfDeclarationOnNextline:true
#允许在同一行上使用短块
AllowShortBlocksOnASingleLine:false
#允许在同一行上使用短格标签
AllowShortCaselLabelSonaSingleLine:false
#允许将短函数放在同一行上:无、InlineOnly(在类中定义)、Empty(空函数)、Inline(在类中定义、空函数)、All
AllowShortFunction单线:无
#允许简短的if语句保持在同一行上
AllowShortIfStatementsOnASingleLine:false
#允许短循环保持在同一线路上
AllowShortLoopsOnASingleLine:false
#定义返回类型后始终中断(已弃用)
AlwaysBreakAfterDefinition返回类型:无
#始终在返回类型后换行:None、All、TopLevel(顶级函数、类中未包含的函数),
#AllDefinitions(所有定义,不包括声明)、TopLevelDefinitions(所有顶级函数的定义)
AlwaysBreakAfterReturnType:无
#始终在多行字符串文字之前换行
AlwaysBreakbefore多重限制:false
#始终在模板语句后换行
AlwaysBreakTemplate声明:false
#false表示函数参数要么在同一行上,要么在各自的行上
BinPackArguments:true
#false表示所有形式参数要么在同一行上,要么在各自的行上
BinPackParameters:正确
#大括号换行,仅当BreakBeforeBrages设置为“自定义”时有效
#二进制运算符前的换行符:无(运算符后的换行符)、不赋值(非赋值运算符前的换行符)、全部(运算符前的换行符)
BreakBeforeBaryOperators:不指定
#在大括号前换行:Attach(始终将大括号附加到周围的上下文)、Linux(函数、名称空间和类定义除外,类似于Attach),
#Mozilla(枚举、函数、记录定义除外,类似于附件)、Stroustrup(函数定义除外,catch,否则类似于附件),
#Allman(总是在大括号之前断开)、GNU(总是在大括号之前断开,并在控制语句的大括号中添加额外的缩进)、WebKit(函数之前的换行符)、Custom
#注意:我们认为语句块也属于函数
BreakBeforeBraces:自定义
#三元运算符前的中断
BreakBeforeTernaly运算符:true
#在构造函数的初始化列表中,逗号前有一个分隔符
BreakConstructorInitializersBeforeComa:false
BreakConstructorInitializers:BeforeConon
BreakAfterJavaFieldAnnotations:false
BreakStringLiterals:true
#用特殊含义描述注释的正则表达式,不应分成多行或以其他方式更改
注释pragma:“^IWYU pragma:”
#构造函数的初始化列表要么全部在同一行上,要么在各自的行上
构造函数初始化LonOneLine或NeperLine:true
#所有施工人员的舒适清单
AllowAllConstructorInitializerOnnextline:false
#压痕宽度为0
# AlignConsecutiveBitFields: false
# AlignOperands:   Align
# AllowShortEnumsOnASingleLine: true
#  BeforeLambdaBody: false
#  BeforeWhile:     false
# IndentCaseBlocks: false
# IndentExternBlock: AfterExternBlock
# InsertTrailingCommas: None
# ObjCBreakBeforeNestedBlockParam: true
# WhitespaceSensitiveMacros:
#  - STRINGIZE
#  - PP_STRINGIZE
#  - BOOST_PP_STRINGIZE