Your second handfull of VS2008 Shortcuts

In my previous article about keyboards shortcuts I promised a follow-up.

Well, here it is:

Many of the keyboard shortcuts in Visual Studio are chords. This means that the shortcut is actually a sequence of keypresses. (So with the first one mentioned here, you’ll first press and hold the CTRL-key while pressing K first, and after releasing K you press D.)

So I hereby introduce you to some really usefull chords:

  • CTRL+K, CTRL+D to reformat the current file. (Some call it prettyprint…)
    This one is important, because it will help you get rid of “visual bugs”. (Ie. code that looks right because of incorrect indentation.)
    When opening a files someone else has worked on, I always start with this one.
  • CTRL+K, CTRL+C to comment out and CTRL+K, CTRL+U to uncomment the current line or the selection. (This really is much better than using /* and */ to comment out blocks of code, since it actually works with nested comments.)

Many of the refactoring shortcuts is Visual Studio are chords as well. The one I use the most is probably CTRL+R, CTRL+R (yes, thats twice the same key) to select the rename refactoring.

  • CTRL+R, CTRL+M to turn the selected statements into a method, and create a call to that method. It will bring in the necessary parameters too! (It’s called Refactor->Extract Method on the right-click context-menu.)
  • CTRL+R, CTRL+P to promote a local variable to a parameter. (I seldom use its CTRL+R, CTRL+V counterpart.)

More of them are described in this PDF from Microsoft. It shows the default keyboard shortcuts for VS2008 for a C# developer, and has a section on refactoring.