C++ EditorConfig formatting conventions (original) (raw)

You can add EditorConfig files to your project to configure C++ formatting to enforce a consistent code style for everyone contributing to the project. Both Visual Studio and Visual Studio Code have built-in EditorConfig support for each of the global Visual Studio C++ formatting settings. The EditorConfig settings are stored in an .editorconfig file. When that file is present in your project, it takes precedence over the Visual Studio formatting settings.

This document lists all the EditorConfig C++ formatting settings supported by Visual Studio and Visual Studio Code.

For more information about:

C++ formatting conventions

C++ formatting EditorConfig settings are prefixed with cpp_. Here's an example of what an .editorconfig file might look like:

[*.{c++,cc,cpp,cxx,h,h++,hh,hpp,hxx,inl,ipp,tlh,tli}]

cpp_indent_case_contents_when_block = true
cpp_new_line_before_open_brace_namespace = same_line

The rest of this document lists all the EditorConfig C++ formatting settings supported by Visual Studio and VS Code.

Indentation settings

Indent braces

Indent each line relatively to

Within parentheses, align new lines when I type them

In existing code, do not use the setting for alignment of new lines within parentheses

Indent case contents

Indent case labels

Indent braces following a case statement

Indent braces of lambdas used as parameters

Position of goto labels

Position of preprocessor directives

Indent access specifiers

Indent namespace contents

Preserve indentation of comments

Newline settings

Position of open braces for namespaces

Position of open braces for types

Position of open braces for functions

Position of open braces for control blocks

Position of open braces for lambdas

Place scope braces on separate lines

For empty types, move closing braces to the same line as opening braces

For empty function bodies, move closing braces to the same line as opening braces

Place 'catch' and similar keywords on a new line

Place 'else' on a new line

Place 'while' in a do-while loop on a new line

Spacing settings

Spacing between function names and opening parentheses of argument lists

Insert space within parentheses of an argument list

Insert space between parentheses when argument list is empty

Insert space between keyword and opening parenthesis in control flow statements

Insert space within parentheses of a control statement

Insert space before opening parenthesis of lambda argument lists

Insert space within parentheses of a C-style cast

Insert space after closing parenthesis of C-style cast

Insert space within parentheses of a parenthesized expression

Insert space before opening brace of blocks

Insert space between empty braces

Insert space before opening brace of uniform initialization and initializer lists

Insert space within braces of uniform initialization and initializer lists

Preserve spaces inside uniform initialization and initializer lists

Insert space before opening square brackets

Insert space within square bracket

Insert space before empty square brackets

Insert space between empty square brackets

Group square brackets for multi-dimensional arrays together

Insert space within square brackets for lambdas

SpaceBetweenEmptyLambdaBrackets

Insert space before commas

Insert space after commas

Remove spaces before and after member operators

Insert space before colon for base in type declarations

Insert space before colon for constructors

Remove space before semicolons

Insert space after semicolons

Remove spaces between unary operators and their operands

Spacing for binary operators

Spacing for assignment operators

Pointer/reference alignment

Spacing for conditional operators

Wrapping options

Wrapping options for blocks

See also