Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual studio Reformat Code/Document

Tags:

I can't find the Reformat button, I know I can use ctrl+k+d, but I wish to have also the toolbar with the button. can someone help me ?

like image 732
Erez Avatar asked May 29 '11 12:05

Erez


People also ask

How do I format an entire document in Visual Studio?

As long as your code is syntactically correct (i.e. no stray brackets or End Ifs without matching Ifs), Visual Studio will reformat your whole file with one key chord: Hold down the Control key and then press K, followed by D. Boom!

How do I clean up code in VS Code?

You can also run code cleanup across your entire project or solution. Right-click on the project or solution name in Solution Explorer, select Analyze and Code Cleanup, and then select Run Code Cleanup.

How do I Auto Arrange codes in Visual Studio?

To automatically format the file on save, In Visual Studio Code, press Control + Shift + P or Command + Shift + P (Mac) to open the command palette and type setting and then select Preferences: Open User Settings option. Search for format on save setting and check the checkbox.


2 Answers

You can use Edit > Advanced > Format Document and you can also move this as a button to any toolbar. Go to Tools > Customize > Commands, select Toolbar and push Add Command button. Then select Edit category and find Document Format.

like image 112
Ladislav Mrnka Avatar answered Sep 20 '22 13:09

Ladislav Mrnka


Apparently VS2010 (maybe others) hide certain commands depending on the style you choose. I chose Web Dev (code) as my choice and the Document Format is not present to be added to a toolbar. But, if I change to C# Code (tools>Import/Export) then the Document Format command is right there in the Edit menu where others here have said it is.

I had to import the C# Dev layout, but unchecked colors and code formatting options (so it won't overwrite those). What section you must import to get the format document button, I don't know, I didn't experiment that deep.

Seems stupid MS chose to force us down specific paths for layout with no convenient way to get out of it.

like image 45
Wolfie Avatar answered Sep 21 '22 13:09

Wolfie