How to automatically indent source code?

2019-01-16 03:39发布

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?

7条回答
老娘就宠你
2楼-- · 2019-01-16 04:26

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.

查看更多
The star\"
3楼-- · 2019-01-16 04:28

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

enter image description here

查看更多
Lonely孤独者°
4楼-- · 2019-01-16 04:30

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...

查看更多
贼婆χ
5楼-- · 2019-01-16 04:35

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.

查看更多
劫难
6楼-- · 2019-01-16 04:37

In 2010 it is ctrl +k +d for indentation

查看更多
Juvenile、少年°
7楼-- · 2019-01-16 04:43

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.

查看更多
登录 后发表回答