Visual Studio 2013: Format the Current Document or Selection
NOTE: This is an older feature. I’ve updated the information for VS2013.
This one is a little known feature you can take advantage of when working with your code. Assuming you have some unformatted code:
You can format the entire document by going to Edit -> Advanced -> Format Document (CTRL+K, CTRL+D) to get this:
You can also do this with just a selection of code:
Go to Edit -> Advanced -> Format Selection (CTRL+K, CTRL+F) to get this:
I won’t go deep into it here but it’s important to remember that the automated formatting follows the default rules you can easily change by going to Tools | Options | Text Editor | [Language] | Formatting in most cases. For example, to change the HTML rules go to Tools | Options | Text Editor | HTML | Formatting:
In the case of HTML, you can go pretty deep into the formatting options by clicking on the Tag Specific Options button:
Formatting the document or selection is a great way to make your code more readable. Enjoy!