Skip to content

Commit d04ac42

Browse files
Learn Build Service GitHub AppLearn Build Service GitHub App
authored andcommitted
Merging changes synced from https://github.com/MicrosoftDocs/visualstudio-docs-pr (branch live)
2 parents e358470 + fc2930f commit d04ac42

File tree

2 files changed

+28
-18
lines changed

2 files changed

+28
-18
lines changed

docs/ide/cpp-editorconfig-properties.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: "C++ EditorConfig formatting conventions"
33
titleSuffix: ""
44
description: "Learn about how to use EditorConfig to format C++ code in Visual Studio."
5-
ms.date: 9/14/2020
5+
ms.date: 08/22/2024
66
author: jureid
77
ms.author: ghogen
88
manager: mijacobs
@@ -11,17 +11,23 @@ dev_langs:
1111
- CPP
1212

1313
ms.topic: reference
14-
monikerRange: vs-2019
1514
---
1615
# C++ EditorConfig formatting conventions
1716

18-
The Visual Studio C++ formatter has a rich set of configurable settings that can be applied globally. To set C++ formatting settings for a specific workspace, use [clangformat](https://clang.llvm.org/docs/ClangFormat.html) or [EditorConfig](https://editorconfig.org/). Both Visual Studio and Visual Studio Code have built-in EditorConfig support for each of the global Visual Studio C++ formatting settings, with the EditorConfig settings taking precedence. This means you can add EditorConfig files to your workspace to configure C++ formatting on a more granular level and enforce consistent code style for everyone contributing to the project.
17+
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](https://editorconfig.org/) 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.
18+
19+
This document lists all the EditorConfig C++ formatting settings supported by Visual Studio and Visual Studio Code.
20+
21+
For more information about:
22+
23+
- Using an EditorConfig file in Visual Studio, see [Define consistent coding styles with EditorConfig](create-portable-custom-editor-options.md).
24+
- Manually create an EditorConfig file based on clang formatting settings, see [clangformat](https://clang.llvm.org/docs/ClangFormat.html). Rename that file `.editorconfig` and save it in your project.
1925

2026
## C++ formatting conventions
2127

22-
C++ formatting EditorConfig settings are prefixed with `cpp_`. Here's an example of what your EditorConfig file might look like:
28+
C++ formatting EditorConfig settings are prefixed with `cpp_`. Here's an example of what an `.editorconfig` file might look like:
2329

24-
```ini
30+
```
2531
[*.{c++,cc,cpp,cxx,h,h++,hh,hpp,hxx,inl,ipp,tlh,tli}]
2632
2733
cpp_indent_case_contents_when_block = true

docs/ide/create-portable-custom-editor-options.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@ ms.date: 04/01/2024
1515
---
1616
# Define consistent coding styles with EditorConfig
1717

18-
To enforce consistent coding styles for everyone that works in a codebase, you can add an EditorConfig file to your solution or project. EditConfig file settings adhere to a file format specification maintained by [EditorConfig.org](https://editorconfig.org). Many code editors and applications support EditorConfig files, including Visual Studio. It's a portable component that travels with your code, and can enforce coding styles even outside of Visual Studio.
18+
To enforce consistent coding styles for everyone that works in a codebase, you can add an `.editorConfig` file to your solution or project. EditorConfig file settings adhere to a file format specification maintained by [EditorConfig.org](https://editorconfig.org). Many code editors and applications support EditorConfig files, including Visual Studio. Because the settings are in a file, they accompany your code, and can be used even outside of Visual Studio.
1919

20-
In Visual Studio, EditorConfig file settings take precedence over the global text editor settings (accessed by selecting **Text Editor** in the **Tools** > **Options** dialog box). This means that you can tailor each codebase to use text editor settings that are specific to that project. When you use EditorConfig files, you can still continue to set your own personal editor preferences in the Visual Studio text editor. These text editor settings apply whenever you're working in a codebase without an EditorConfig file, or when the EditorConfig file doesn't override a particular setting. An example of such a preference is whether to use tabs or spaces for the code indent style.
20+
In Visual Studio, EditorConfig file settings take precedence over the various global text editor settings available under **Tools** > **Options** > **Text Editor** > **C/C++** > **Code Style**. You can use an EditorConfig file to tailor each codebase to use text editor settings that are specific to that project.
21+
22+
You can manually populate an EditorConfig file, or automatically generate it based on the code style settings you've chosen in Visual Studio. To create a new `.editorconfig` file based on your current Visual Studio settings, from the Visual Studio main menu choose **Tools** > **Options** > **Text Editor** > **C/C++** > **General**. Then choose **Generate .editorconfig file from settings**. Choose the folder where your project is and then choose **Select Folder** to save the `.editorconfig` file.
23+
24+
When you use an EditorConfig file, you can still continue to set your own personal editor preferences in the Visual Studio text editor. These text editor settings apply whenever you're working in a codebase without an EditorConfig file, or when the EditorConfig file doesn't override a particular setting. An example of such a preference is whether to use tabs or spaces for the code indent style.
2125

2226
When you add an EditorConfig file to your project in Visual Studio, only new lines of code are formatted based on the EditorConfig settings. The formatting of existing code isn't changed unless you run one of the following commands:
2327

@@ -38,7 +42,7 @@ EditorConfig file settings let you maintain consistent coding styles and convent
3842

3943
EditorConfig files are useful when coding conventions you use on your personal projects differ from those conventions used on your team's projects. For example, you might prefer that an indent adds a tab character in your code. However, your team might prefer that an indent adds four space instead. EditorConfig files resolve this problem by letting you have a configuration for each scenario.
4044

41-
Because an *.editorconfig* file in the codebase contains the EditorConfig settings, they travel along with that codebase. As long as you open the code file in an EditorConfig-compliant editor, the text editor settings are activated.
45+
Because an `.editorconfig` file in the codebase contains the EditorConfig settings, they travel along with that codebase. As long as you open the code file in an EditorConfig-compliant editor, the text editor settings are activated.
4246

4347
::: moniker range="<=vs-2019"
4448
> [!NOTE]
@@ -72,7 +76,7 @@ If you remove an EditorConfig file from your project or codebase, you must close
7276

7377
To add an EditorConfig file to your project or solution, follow these steps:
7478

75-
1. Open a project or solution in Visual Studio. Select either the solution or project node, depending on whether your EditorConfig settings should apply to all projects in the solution or just one. You can also select a folder in your project or solution to add the *.editorconfig* file to.
79+
1. Open a project or solution in Visual Studio. Select either the solution or project node, depending on whether your EditorConfig settings should apply to all projects in the solution or just one. You can also select a folder in your project or solution to add the `.editorconfig` file to.
7680

7781
1. From the menu, choose **Project** > **Add New Item**, or press **Ctrl**+**Shift**+**A**.
7882

@@ -86,7 +90,7 @@ To add an EditorConfig file to your project or solution, follow these steps:
8690

8791
1. Select the **editorconfig File (empty)** template to add an EditorConfig file prefilled with default EditorConfig options for whitespace, code style, and naming conventions. Or, select the **editorconfig File (.NET)** template to add an EditorConfig file prefilled with default [.NET whitespace, code style, and naming conventions](/dotnet/fundamentals/code-analysis/code-style-rule-options).
8892

89-
A new *.editorconfig* file appears in Solution Explorer, and opens in the editor as a new tab.
93+
A new `.editorconfig` file appears in Solution Explorer, and opens in the editor as a new tab.
9094

9195
::: moniker range=">= vs-2022"
9296
:::image type="content" source="media/vs-2022/editorconfig-dotnet-new.png" alt-text="Screenshot that shows the .editorconfig file in Solution Explorer and editor.":::
@@ -98,23 +102,23 @@ To add an EditorConfig file to your project or solution, follow these steps:
98102

99103
There are a couple of other ways you can add an EditorConfig file to your project:
100104

101-
- Use [IntelliCode for Visual Studio](/visualstudio/ide/intellicode-visual-studio) to generate an *.editorconfig* file in your solution. Right-click in Solution Explorer and choosing **Add** > **New EditorConfig (IntelliCode)** from the context menu. IntelliCode for Visual Studio infers your code styles from existing code, and then creates an EditorConfig file with your code-style preferences predefined.
105+
- Use [IntelliCode for Visual Studio](/visualstudio/ide/intellicode-visual-studio) to generate an `.editorconfig` file in your solution. Right-click in Solution Explorer and choosing **Add** > **New EditorConfig (IntelliCode)** from the context menu. IntelliCode for Visual Studio infers your code styles from existing code, and then creates an EditorConfig file with your code-style preferences predefined.
102106

103107
- [Automatically generate an EditorConfig file based on your code-style settings](code-styles-and-code-cleanup.md#code-styles-in-editorconfig-files).
104108

105109
## File hierarchy and precedence
106110

107-
When you add an *.editorconfig* file to a folder in your file hierarchy, its settings apply to all applicable files at that level and lower. You can also override EditorConfig settings for a particular project, codebase, or part of a codebase, such that it uses different conventions than other parts of the codebase. Doing so can be useful when you incorporate code from somewhere else, and don’t want to change its conventions.
111+
When you add an `.editorconfig` file to a folder in your file hierarchy, its settings apply to all applicable files at that level and lower. You can also override EditorConfig settings for a particular project, codebase, or part of a codebase, such that it uses different conventions than other parts of the codebase. Doing so can be useful when you incorporate code from somewhere else, and don’t want to change its conventions.
108112

109113
Follow these guidelines:
110114

111-
- To override some or all of the EditorConfig settings, add an *.editorconfig* file at the level of the file hierarchy you want those overridden settings to apply. The new EditorConfig file settings apply to files at the same level and files in any subdirectories.
115+
- To override some or all of the EditorConfig settings, add an `.editorconfig` file at the level of the file hierarchy you want those overridden settings to apply. The new EditorConfig file settings apply to files at the same level and files in any subdirectories.
112116

113117
:::image type="content" source="../ide/media/vside_editorconfig_hierarchy.png" alt-text="Screenshot that shows the EditorConfig hierarchy.":::
114118

115-
- If you want to override some, but not all of the settings, specify just those settings in the *.editorconfig* file. Only those properties that you explicitly list in the lower-level *.editorconfig* file are overridden. Other settings from any higher-level *.editorconfig* files continue to apply.
119+
- If you want to override some, but not all of the settings, specify just those settings in the `.editorconfig` file. Only those properties that you explicitly list in the lower-level `.editorconfig` file are overridden. Other settings from any higher-level `.editorconfig` files continue to apply.
116120

117-
- If you want to ensure that no settings from any higher-level *.editorconfig* files are applied to this part of the codebase, add the `root=true` property to the lower-level *.editorconfig* file.
121+
- If you want to ensure that no settings from any higher-level `.editorconfig` files are applied to this part of the codebase, add the `root=true` property to the lower-level `.editorconfig` file.
118122

119123
```ini
120124
# top-most EditorConfig file for this level
@@ -167,7 +171,7 @@ The following example shows the indent state of a C# code snippet before and aft
167171
::: moniker-end
168172

169173
::: moniker range="vs-2019"
170-
Add a new file named *.editorconfig* to the project, with the following contents. The `[*.cs]` indicator means that this change applies only to C# code files in the project.
174+
Add a new file named `.editorconfig` to the project, with the following contents. The `[*.cs]` indicator means that this change applies only to C# code files in the project.
171175

172176
```ini
173177
# Top-most EditorConfig file
@@ -209,9 +213,9 @@ To troubleshoot EditorConfig issues, follow these steps:
209213
dir .editorconfig /s
210214
```
211215

212-
1. To control the scope of your EditorConfig conventions, set the `root=true` property in the *.editorconfig* file at the root of your repo or in the directory that your project resides.
216+
1. To control the scope of your EditorConfig conventions, set the `root=true` property in the `.editorconfig` file at the root of your repo or in the directory that your project resides.
213217

214-
Visual Studio looks for a file named *.editorconfig* in the directory of the opened file and in every parent directory. The search ends when it reaches the root filepath, or if an *.editorconfig* file with `root=true` is found.
218+
Visual Studio looks for a file named `.editorconfig` in the directory of the opened file and in every parent directory. The search ends when it reaches the root filepath, or if an `.editorconfig` file with `root=true` is found.
215219

216220
## Related content
217221

0 commit comments

Comments
 (0)