How to auto format code in VS2012 to save time typing and deleting spaces and tabs?
-
6or just 'Ctrl - E, D' if your IDE is set up as mine is. – paul Apr 17 '13 at 13:58
-
You can use only "Crtl + E, D". That's work on the entire document. – Xaruth Apr 17 '13 at 13:59
-
http://stackoverflow.com/questions/13123479/format-code-strg-k-d-in-vs-2012 ... – Xaruth Apr 17 '13 at 14:03
-
Sorry. Re-Worded to match Stack Overflow format. – mitaka Apr 17 '13 at 15:18
-
1I tried "Ctrl + E, D" in my Visual Studio 2012, Update 2 installation, but nothing is happening. Probably I am missing some settings. – mitaka Apr 17 '13 at 15:24
-
1Keep getting negatives for this question. Should I delete it if it doesn't help anybody? – mitaka Apr 19 '13 at 14:26
2 Answers
If you are looking to format the code as you enter the text, there are some additional settings in Tools\Options\Text Editor area.
Since your example appears to be a config file (XML) look at the XML editor.
Otherwise, to format at any time, the suggestions from @mitaka and @Xaruth are good.
Be aware that the keystrokes to activate Format Document and Format Selection are different depending on what Development Settings you have active in Visual Studio. To see which keystrokes are assigned to the command in your copy of VS look in the Edit menu.
![](../../users/profiles/351218.webp)
- 6,662
- 1
- 26
- 34
I use the following combination to auto format indentations of my code in VS2012.
Unformatted code bock in web.config:
Ctrl + A to select all the code in a file to be formatted in VS2012. Or you can select just a block of the code manually.
Ctrl + K, then Ctrl + F will format the code with proper indentations.
Formatted code block
![](../../users/profiles/2142001.webp)
- 2,069
- 1
- 27
- 30