Visual Studio Shortcut: Format Document (Ctrl+K, Ctrl+D)

1 minute read

Code formatting really helps indicate the flow of logic in a complex method. It could be a simple as indenting your method contents and then again for any logic blocks like if or for statements. Or having the whitespace setup in a specific way that makes things readable. To save your hands do yourself a favour and learn Ctrl+K, D , this is handy when you’ve pasted in some code and it’s not in a very good format and hey presto, it fits in with the rest of your file. I did mention this to a few friends and they were surprised I used it so often. Of course you could use format selection, Ctrl+K, F , so it will only format the code you want to but I think that’s an easy way out. ##Formatting Options

The best way to make the most of it is to understand the formatting options. That’s where it can get a little fiddly because each language has different formatting options. In the case of CSS shown below it’s pretty limited but it’s very easy to change. While you’re tweaking your formatting options it’s worth checking your code into source control until you get it looking how you’d like. ##Let go

You might still be thinking that the code formatter won’t format your code just so and you’re right. A few things will be out place but you’ll get to used to it and with all the free time you can do something more productive ;)

Leave a Comment