Ask Learn
Preview
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Menu: Edit -> Advanced -> Tabify Selected Lines; Edit -> Advanced -> Untabify Selected Lines
Command: Edit.TabifySelectedLines; Edit.UntabifySelectedLines;Edit.ConvertTabsToSpaces;Edit.ConvertSpacesToTabs
Versions: 2008,2010
Published: 3/14/2010
Code: vstipEdit0028
Some people prefer spaces, others prefer tabs. Well you can have it any way you want it with this next item. You can convert spaces to tabs and convert tabs to spaces on your selected lines. There are a couple of ways to do this and each has different results:
Tabify / Untabify
If all you want to do is convert leading spaces to tabs (or vice versa) then you would use the Tabify/Untabify commands. First, start out with a line with some leading spaces (NOTE: You don't have to select the entire line for this to work as long as any part of the line is selected it will perform the action):
Now go to Edit -> Advanced -> Tabify Selected Lines:
And you should get the leading spaces converted to tabs:
Obviously, to change leading tabs to spaces you would use Untabify Selected Lines:
ConvertSpacesToTabs / ConvertTabsToSpaces
Okay, so what if you want ALL spaces to tabs? Well you have to use a command to do that and will have to make a custom keyboard mapping. The commands you are interested in are Edit.ConvertTabsToSpaces and Edit.ConvertSpacesToTabs. Here is what ConvertSpacesToTabs does to our example (NOTE: For these commands you have to select everywhere you want to convert it will not automatically convert the entire line in case you just want to convert a part of the line):
As you can see, almost all spaces are converted to tabs. Since spaces are converted to tabs in increments of 4, if you have, say, 6 spaces it will result in a tab and 2 spaces left over. That is why there are some left over spaces in the example. And, naturally, if we select these lines and run ConvertTabsToSpaces this will be the result:
And now you know how to convert tabs to spaces and spaces to tabs. Have fun!
Anonymous
March 13, 2010
The company I work for requires tabs, although I prefer spaces since I often copy and paste code into forums, where tabs are ignored or take up too much room. I didn't know about this feature, but it seems like it will allow me to keep tabs as the default setting and then quickly switch to spaces before copying code; then a quick Ctrl+K+D and I'm back to tabs.
Anonymous
March 13, 2010
I prefer tabs by the zain thanks for posting this blog honestly before reading this blog i do not know the shortcuts in visual studio.
Anonymous
March 14, 2010
In Visual Studio 2005/8, these function don't do what their names say they do (in VS2003 and earlier, they actually did what their names said that they did, and I was very sad when they changed). They only convert leading tabs and spaces. If you want to convert all tabs and spaces, you now need to use Edit.ConvertTabsToSpaces and Edit.ConvertSpacesToTabs, which do not exist in the menus.
See Sara's original tip: http://blogs.msdn.com/saraford/archive/2005/06/14/429133.aspx
(Thanks to Sara for pointing me at the function that does what Untabify did in VS2003 and earlier.)
Anonymous
March 14, 2010
The comment has been removed
Anonymous
March 15, 2010
Even though it is only leading tabs/spaces these are very useful. I have worked on files that contain a mix of tabs and spaces and if you work in an editor that has anything other than the same tab stops as the person that inserted the tabs, reading the code can get ugly fast. This is a quick way to get the problem out of the way
Anonymous
March 15, 2010
The comment has been removed
Anonymous
December 15, 2010
The comment has been removed
Anonymous
December 15, 2010
Alice --- are you saying the the Tabify command converted your tabs to spaces?
Anonymous
November 07, 2012
I have a problem with Visual Studio 2012. There is not this option in Edit-advance. Do you know if should I download any extention. Thanks in advance.
Anonymous
November 08, 2012
Oscar,
I've had issues with the context chaning for the main menu system. Make sure you click in the editor first THEN Edit -> Advanced. Let me know if that works.
Z
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign in