sorry for random

Every now and then I find myself in Visual Studio and I’m tempted to edit some source code (usually this happens in the middle of debugging something). Then alarm bells go off and I’m reminded of the pain of cleaning up my patches after visual studio has littered them with tabs and CRLF’s.

Turns out you can tell Visual Studio to stop doing that. Go to tool->options and expand the “Text editor” node and the “All Languages” node under that. Then select tabs under that. I set my indenting to “smart”, tab and indent size to 2 and (this is the key) enabled “Insert spaces”. Its the “Insert Spaces” option that tells VS to use spaces instead of tabs.

The Conversation {2 comments}

A helpful shortcut is Ctrl-R, Ctrl-W which toggles displaying whitespace. There’s also Ctrl-K, Ctrl-F which reformats the selection according to your editor preferences, but I don’t know if that works on C++.

The way to get around this is via a .vssettings file. When I first started with VS 2005, I set the tabs/spaces default in each language. You can do this via Tools -> Options -> Text Editor -> (C#/C++). Then I export the tab settings into a .vsssettings file. Whenever I install VS on a new machine I just import that file and I have my happy space/tab settings.