A Developer's Diary

Apr 3, 2010

Visual Studio - Auto formatting your code

Whenever you paste any code from other applications into a source file within Visual Studio, the formatting gets messed up. You can use the following tip to format the code if written in C++, C# and VB

Steps

1. Select the text portion to format OR (Ctrl + a)
2. Hold Ctrl and hit k followed by f (Ctrl + k + f)


To autoformat the code written in html and xml use the following tip
Steps

1. Select the text portion to format OR (Ctrl + a)
2. Hit Ctrl + k followed by Ctrl + d

3 comments :

Anonymous said...

Don't need to select all before CTRL-K, CTRL-D. Cheers!

Nenad Bulatovic said...

If you are using VS2010/2012 you can give a try to free VS extension:

[AStyle][1]


[1]: http://visualstudiogallery.msdn.microsoft.com/2f3f04cd-2866-4e47-a671-d1cc9cc3fb02

Anonymous said...

Another extension to automatically format code on any edit is Continuous Formatting:
https://visualstudiogallery.msdn.microsoft.com/08afc8d1-4b74-44df-b012-f225ee9e9220

Post a Comment