How to automatically indent source code?

Visual Studio-2010Visual StudioIndentation

Visual Studio-2010 Problem Overview


How can I automatically indent source code in Visual Studio 2010?

I have used Ctrl + K, Ctrl + F, but it does not work; is there any other way/plugin to do this?

Visual Studio-2010 Solutions


Solution 1 - Visual Studio-2010

Ctrl+E, D - Format whole doc
Ctrl+K, Ctrl+F - Format selection

Also available in the menu via Edit|Advanced.

Thomas

Edit-
Ctrl+K, Ctrl+D - Format whole doc in VS 2010

Solution 2 - Visual Studio-2010

In 2010 it is Ctrl+k, Ctrl+d. See image below.

enter image description here

Solution 3 - Visual Studio-2010

In Visual Studio 2010

Ctrl +k +d indent the complete page.

Ctrl +k +f indent the selected Code.

For more help visit : http://msdn.microsoft.com/en-us/library/da5kh0wa.aspx

every thing is there.

Solution 4 - Visual Studio-2010

In 2010 it is ctrl +k +d for indentation

Solution 5 - Visual Studio-2010

Also, there's the handy little "increase indent" and "decrease indent" buttons. If you highlight a block of code and click those buttons the entire block will indent.

Solution 6 - Visual Studio-2010

> > I have tried both ways, and from the Edit|Advanced menu, and they are not doing anything to my source code. Other options like line indent are working. What could be wrong? – Chucky Jul 12 '13 at 11:06

Sometimes if it doesnt work, try to select a couple lines above and below or the whole block of code (whole function, whole cycle, whole switch, etc.), so that it knows how to indent.

Like for example if you copy/paste something into a case statement of a switch and it has wrong indentation, you need to select the text + the line with the case statement above to get it to work.

Solution 7 - Visual Studio-2010

It may be worth noting that auto-indent does not work if there are syntax errors in the document. Get rid of the red squigglies, and THEN try CTRL+K, CTRL+D, whatever...

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJichaoView Question on Stackoverflow
Solution 1 - Visual Studio-2010Thomas WellerView Answer on Stackoverflow
Solution 2 - Visual Studio-2010gooddadmikeView Answer on Stackoverflow
Solution 3 - Visual Studio-2010ArmaanView Answer on Stackoverflow
Solution 4 - Visual Studio-2010KsnrgView Answer on Stackoverflow
Solution 5 - Visual Studio-2010Tyler TreatView Answer on Stackoverflow
Solution 6 - Visual Studio-2010JoeShamView Answer on Stackoverflow
Solution 7 - Visual Studio-2010LionelGouletView Answer on Stackoverflow