Visual Studio 2013: Format the Current Document or Selection


NOTE: This is an older feature. I’ve updated the information for VS2013.



Format Document

This one is a little known feature you can take advantage of when working with your code. Assuming you have some unformatted code:

5-16-2012 12-14-43 PM


5-16-2012 12-10-39 PM



You can format the entire document by going to Edit -> Advanced -> Format Document (CTRL+K, CTRL+D) to get this:

5-16-2012 12-16-13 PM


5-16-2012 12-18-01 PM




Format Selection

You can also do this with just a selection of code:

5-16-2012 12-21-01 PM


Go to Edit -> Advanced -> Format Selection (CTRL+K, CTRL+F) to get this:

5-16-2012 12-23-33 PM




Formatting Options

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:

5-16-2012 12-27-47 PM


In the case of HTML, you can go pretty deep into the formatting options by clicking on the Tag Specific Options button:

5-16-2012 12-29-32 PM





Formatting the document or selection is a great way to make your code more readable. Enjoy!