Search code examples
c++visual-studio-2019editorconfig

How to assign .editorconfig to a Visual Studio 2019 C++ solution?


I am editing a VS solution that has a different coding style than the one I normally use. I found in the docs that VS 2019 supports EditorConfig: https://learn.microsoft.com/en-us/visualstudio/ide/create-portable-custom-editor-options?view=vs-2019

I created .editorconfig file in the root of my solution:

enter image description here

I put this in the file:

root = true

[*.{cpp,hpp,h}]
indent_style = space
indent_size = 4

I then went to the solution, right clicked the solution Botcraft in the solution explorer, selected Add an existing item... and added the aforementioned file. I can now see the item in the solution:

enter image description here

However, when I write if(true) and press enter, I still get two spaces as per my VS settings instead of four as per the editorconfig settings.

How to link .editorconfig to visual studio solution and make it respect the settings inside?


Solution

  • EditorConfig files are only applied to the directory they are in and its sub-directories you need to put the file in the same folder as your source code (or a folder above it) not in the same folder as your solution/project files.