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


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

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


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:


[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:

Post a Comment