Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use editorconfig in Visual Studio 2019?

I created .editorconfig file at solution level in VS 2019 with following settings:

root = true

# All files
[*]
indent_style = tab
indent_size = 4
tab_width = 4

Then I restarted the IDE so the changes can take effect. However only .editorconfig file itself uses the selected settings. All other files in my solution still use spaces and not settings defined in the config.

I then placed the .editorconfig file at project level and restarted yet again. No change.

How do I properly use .editorconfig file so all my project files use the settings defined in it?

Note: I am using latest version of VS 2019 Community.

like image 263
sanitizedUser Avatar asked Feb 04 '23 15:02

sanitizedUser


1 Answers

According with documentation, you have to use "Format Document" or "Code cleanup" to apply the format to existing code.

When you add an EditorConfig file to your project in Visual Studio, new lines of code are formatted according to the EditorConfig settings. The formatting of existing code is not changed unless you run one of the following commands:

  • Code Cleanup (Ctrl+K, Ctrl+E), which applies any white space settings, such as indent style, and selected code style settings, such as how to sort using directives.
  • Edit > Advanced > Format Document (or Ctrl+K, Ctrl+D in the default profile), which only applies white space settings, such as indent style.

Source: https://learn.microsoft.com/en-us/visualstudio/ide/create-portable-custom-editor-options?view=vs-2019

like image 134
Javier Ros Avatar answered Mar 16 '23 12:03

Javier Ros