In Eclipse there is a shortcut, Ctrl+Shift+F, that re-indents code and fixes comments and blank lines. Is there an equivalent for Visual Studio 2010?
- VS does a subset of what Eclipse does. VS does not fix blank lines, nor reflow comments. To get the whole enchilada you need reSharper or something like that.John Henckel– John Henckel2014-12-17 15:59:06 +00:00Commented Dec 17, 2014 at 15:59
- Why is this tagged with 3 specific versions of Visual Studio, Visual Studio 2010, Visual Studio 2012, and Visual Studio 2013?Peter Mortensen– Peter Mortensen2019-07-20 10:57:33 +00:00Commented Jul 20, 2019 at 10:57
- 1The corresponding for Visual Studio Code is How do you format code in Visual Studio Code?Peter Mortensen– Peter Mortensen2020-06-13 00:09:52 +00:00Commented Jun 13, 2020 at 0:09
14 Answers
Visual Studio with C# key bindings
To answer the specific question, in C# you are likely to be using the C# keyboard mapping scheme, which will use these hotkeys by default:
Ctrl+E, Ctrl+D to format the entire document.
Ctrl+E, Ctrl+F to format the selection.
You can change these in menu Tools → Options → Environment → Keyboard (either by selecting a different "keyboard mapping scheme", or binding individual keys to the commands "Edit.FormatDocument" and "Edit.FormatSelection").
If you have not chosen to use the C# keyboard mapping scheme, then you may find the key shortcuts are different. For example, if you are not using the C# bindings, the keys are likely to be:
Ctrl + K + D (Entire document)
Ctrl + K + F (Selection only)
To find out which key bindings apply in your copy of Visual Studio, look in menu Edit → Advanced menu - the keys are displayed to the right of the menu items, so it's easy to discover what they are on your system.
6 Comments
Edit.FormatLine in the Keyboard Mapping manager. When you use Git or Svn formating any other lines than the one you are working on result in a lot of useless changes...Ctrl + K + D (Entire document)
Ctrl + K + F (Selection only)
2 Comments
Edit.FormatDocument) some code cleanup also happens, e.g. I have set Add/remove braces for single-line control statements (really bad description because the user has no idea what happens when you activate it^^) so the formatter always changes if(foo) bar; to if(foo) { bar; }. executing Edit.FormatSelection doesn’t change that. Might be a bug, gonna report it if I cannot find anything.Try Ctrl + K + D (don't lift the Ctrl key in between).
2 Comments
Yes, you can use the two-chord hotkey (Ctrl+K, Ctrl+F if you're using the General profile) to format your selection.
Other formatting options are under menu Edit → Advanced, and like all Visual Studio commands, you can set your own hotkey via menu Tools → Options → Environment → Keyboard (the format selection command is called Edit.FormatSelection).
Formatting doesn't do anything with blank lines, but it will indent your code according to some rules that are usually slightly off from what you probably want.
3 Comments
Simply
For Visual Studio Code Use Alt+Shift+F
for Visual Studio IDE Press Ctrl+K followed by Ctrl+D
It will beautify/format your entire file.
1 Comment
Most easy, try once:
- Select all codes using: Ctrl+A
- Press: Ctrl+K+D

