How to automatically indent source code?

自闭症网瘾萝莉.ら 提交于 2019-11-28 03:07:27
Thomas Weller

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

gooddadmike

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

Armaan

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.

Ksnrg

In 2010 it is ctrl +k +d for indentation

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.

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!