249
votes

Is there a way to set TAB button to work as 4 spaces in Visual Studio 2010 instead of going to Edit->Advanced->Untabify Selected Lines?

6
+1 since within the question there is the hint how to untabify already existent sources, the accepted answer applies only for new sourcesShmil The Cat
Would somebody mind editing the "2010" out of the question title? This is applicable to many visual studio versions, and the UI is still the same for this part of the IDE for VS 2010, 2013, and 2015. Also it might help to add something to the question that implies that the OP is looking to set the style of new sources; the trick for editing existing sources is cool though.jrh
Also note that "Tabify" and "Untabify" for existing source code files does not work for tabs inserted in the middle of the line, i.e., <tab> int <tab> x; would be replaced with <spaces> int <tab> x;, not <spaces> int <spaces> x;jrh
I am using Visual Studio Community for Mac and instead of untabify, I did Edit>Format>Format Document.Mahdi

6 Answers

351
votes

You can edit this behavior in:

Tools->Options->Text Editor->All Languages->Tabs

Change Tab to use "Insert Spaces" instead of "Keep Tabs".

Note you can also specify this per language if you wish to have different behavior in a specific language.

9
votes

For VS2010 and above (VS2010 needs a plugin). If you have checked/set the options of the tab size in Visual Studio but it still won't work. Then check if you have a .editorconfig file in your project! This will override the Visual Studio settings. Edit the tab-size in that file.

This can happen if you install an Angular application in your project with the Angular-Cli.

See MSDN blog

8
votes

None of these answer were working for me on my macbook pro. So what i had to do was go to:

Preferences -> Source Code -> Code Formatting -> C# source code.

From here I could change my style and spacing tabs etc. This is the only project i have where the lead developer has different formatting than i do. It was a pain in the butt that my IDE would format my code different than theirs.

4
votes

If you don't see the formatting option, you can do Tools->Import and Export settings to import the missing one.

3
votes

First set in the following path Tools->Options->Text Editor->All Languages->Tabs if still didn't work modify as mentioned below Go to Edit->Advanced->Set Indentation ->Spaces

3
votes

For Visual Studio 2019 users:

By the comment under accepted answer, link:

Well... This is "almost" still the same in VS 2019... if you already done that and seems not to work, go to: Tools > Options, and then Text Editor > Advanced > Uncheck "Use adaptive formatting" as seen here