1. sln同级目录下,放一个clang-format文件

    image.png

    1. vs插件设置

    image.png

    1. 安装format on save 插件并启用.

    image.png

    下面是.clang-format文件是从qt-creator抄的,改变了一下括号的换行.

    1. # .clang-format for Qt Creator
    2. #
    3. # This is for clang-format >= 5.0.
    4. #
    5. # The configuration below follows the Qt Creator Coding Rules [1] as closely as
    6. # possible. For documentation of the options, see [2].
    7. #
    8. # Use ../../tests/manual/clang-format-for-qtc/test.cpp for documenting problems
    9. # or testing changes.
    10. #
    11. # In case you update this configuration please also update the qtcStyle() in src\plugins\clangformat\clangformatutils.cpp
    12. #
    13. # [1] https://doc-snapshots.qt.io/qtcreator-extending/coding-style.html
    14. # [2] https://clang.llvm.org/docs/ClangFormatStyleOptions.html
    15. #
    16. ---
    17. Language: Cpp
    18. AccessModifierOffset: -4
    19. AlignAfterOpenBracket: Align
    20. AlignConsecutiveAssignments: false
    21. AlignConsecutiveDeclarations: false
    22. AlignEscapedNewlines: DontAlign
    23. AlignOperands: true
    24. AlignTrailingComments: true
    25. AllowAllParametersOfDeclarationOnNextLine: true
    26. AllowShortBlocksOnASingleLine: false
    27. AllowShortCaseLabelsOnASingleLine: false
    28. AllowShortFunctionsOnASingleLine: Inline
    29. AllowShortIfStatementsOnASingleLine: false
    30. AllowShortLoopsOnASingleLine: false
    31. AlwaysBreakAfterReturnType: None
    32. AlwaysBreakBeforeMultilineStrings: false
    33. AlwaysBreakTemplateDeclarations: true
    34. BinPackArguments: false
    35. BinPackParameters: false
    36. BraceWrapping:
    37. AfterClass: true
    38. AfterControlStatement: false
    39. AfterEnum: false
    40. AfterFunction: true
    41. AfterNamespace: false
    42. AfterObjCDeclaration: false
    43. AfterStruct: true
    44. AfterUnion: false
    45. BeforeCatch: false
    46. BeforeElse: true
    47. IndentBraces: false
    48. SplitEmptyFunction: false
    49. SplitEmptyRecord: false
    50. SplitEmptyNamespace: false
    51. BreakBeforeBinaryOperators: All
    52. BreakBeforeBraces: Custom
    53. BreakBeforeInheritanceComma: false
    54. BreakBeforeTernaryOperators: true
    55. BreakConstructorInitializersBeforeComma: false
    56. BreakConstructorInitializers: BeforeComma
    57. BreakAfterJavaFieldAnnotations: false
    58. BreakStringLiterals: true
    59. ColumnLimit: 120
    60. CommentPragmas: '^ IWYU pragma:'
    61. CompactNamespaces: false
    62. ConstructorInitializerAllOnOneLineOrOnePerLine: false
    63. ConstructorInitializerIndentWidth: 4
    64. ContinuationIndentWidth: 4
    65. Cpp11BracedListStyle: true
    66. DerivePointerAlignment: false
    67. DisableFormat: false
    68. ExperimentalAutoDetectBinPacking: false
    69. FixNamespaceComments: true
    70. ForEachMacros:
    71. - forever # avoids { wrapped to next line
    72. - foreach
    73. - Q_FOREACH
    74. - BOOST_FOREACH
    75. IncludeCategories:
    76. - Regex: '^<Q.*'
    77. Priority: 200
    78. IncludeIsMainRegex: '(Test)?$'
    79. IndentCaseLabels: false
    80. IndentWidth: 4
    81. IndentWrappedFunctionNames: false
    82. JavaScriptQuotes: Leave
    83. JavaScriptWrapImports: true
    84. KeepEmptyLinesAtTheStartOfBlocks: false
    85. # Do not add QT_BEGIN_NAMESPACE/QT_END_NAMESPACE as this will indent lines in between.
    86. MacroBlockBegin: ""
    87. MacroBlockEnd: ""
    88. MaxEmptyLinesToKeep: 1
    89. NamespaceIndentation: None
    90. ObjCBlockIndentWidth: 4
    91. ObjCSpaceAfterProperty: false
    92. ObjCSpaceBeforeProtocolList: true
    93. PenaltyBreakAssignment: 150
    94. PenaltyBreakBeforeFirstCallParameter: 300
    95. PenaltyBreakComment: 500
    96. PenaltyBreakFirstLessLess: 400
    97. PenaltyBreakString: 600
    98. PenaltyExcessCharacter: 50
    99. PenaltyReturnTypeOnItsOwnLine: 300
    100. PointerAlignment: Right
    101. ReflowComments: false
    102. SortIncludes: true
    103. SortUsingDeclarations: true
    104. SpaceAfterCStyleCast: true
    105. SpaceAfterTemplateKeyword: false
    106. SpaceBeforeAssignmentOperators: true
    107. SpaceBeforeParens: ControlStatements
    108. SpaceInEmptyParentheses: false
    109. SpacesBeforeTrailingComments: 1
    110. SpacesInAngles: false
    111. SpacesInContainerLiterals: false
    112. SpacesInCStyleCastParentheses: false
    113. SpacesInParentheses: false
    114. SpacesInSquareBrackets: false
    115. Standard: Cpp11
    116. TabWidth: 4
    117. UseTab: Never