Format the Current Document or Selection
Keyboard: CTRL + K, CTRL + D (document); CTRL + K, CTRL + F (selection)
Menu: Edit -> Advanced -> Format Document; Edit -> Advanced -> Format Selection
Command: Edit.FormatDocument; Edit.FormatSelection
Versions: 2008,2010
Published: 5/19/2010
Code: vstipEdit0057
So, let's say you have some funky code that isn't formatted properly:
And you want it to look good. Just select the code then go to Edit -> Advanced -> Format Selection to get this:
Simple. Easy. Cool.
Comments
Anonymous
January 13, 2012
how can i make either of these a button on a toolbar? when i go to add it i can't find the command in the lists...Anonymous
January 15, 2012
Will :) The commands can be found in the Menu bar area. Change the drop-down to Edit | Advanced. Refer to this post for a refresher on how to work with the commands tab: blogs.msdn.com/.../customize-your-toolbars-in-visual-studio-2010-commands-tab-vstipenv0031.aspxAnonymous
April 26, 2013
That didn't answer his question, which is the same as mine: how to add this to a toolbar so you don't have to drill through menus?Anonymous
April 26, 2013
DC, Actually it did answer the question. The technique I show in the blog post can be used for any menu command. ZAnonymous
February 20, 2014
When I do this, it overrides the tab size settings in the text editor options and uses a larger tab size instead.Anonymous
April 23, 2015
Visual Studio 2013 fails to properly format CSS in HTML documents with this command. It swaps arbitrarily between 2 tabs and 3 tabs of indentation.Anonymous
August 03, 2015
The comment has been removedAnonymous
August 03, 2015
P.S. The instructions I gave are for Visual Studio 2015 so I'm not sure what the procedure for previous versions are but I would think it would be similar. Ragscoon =^_^=