The Visual Studio shell is a big place.  I should know, since I used Visual J++ everyday for a year before joining the team.  As I write these tips, I try to think back to my J++ days to come up with a list of tips and tricks I wish I had known back then and what I now take for granted.  One of these is definitely keyboard binding.  Maybe I didn’t look hard enough for features within Visual Studio.  Maybe I never needed to rebind a command, so I never discovered this.  Anyways, here’s how to do it, so now everyone knows.

To create or change a keyboard shortcut for a given command:

  1. Go to the Tools – Options Dialog and choose Environment – Keyboard
  2. Either type in the command name in the Show commands containing edit box or select the command from the list box.
  3. In the Press shortcut key(s) edit box, press the keyboard shortcut you want to associate with the currently selected command
  4. Press Assign

Binding Keyboard Shortcuts To Commands

If there’s a conflict, the Shortcut currently used by: will show the conflict.  Press Assign to override the conflict.

Note that there are different scopes.  The Use new shortcut in: combo box show the current scope for that particular keyboard shortcut with the Global scope as the default.  For example, keyboard shortcuts assigned in the Text Editor scope will only work when focus is in the text editor (same as code editor).  If you place focus on a tool window and try the same keyboard shortcut, the command that is bound to that keyboard shortcut under global scope will execute.

To find out what command a keyboard shortcut is bound to:

  1. Go to the Tools – Options Dialog and choose Environment – Keyboard
  2. In the Press shortcut key(s) edit box, press the keyboard shortcut you are inquiring about
  3. The Shortcuts for selected command: combo box will either display the associated command(s) – note: make sure to drop down the list if there are multiple keybindings, or the combo box will be empty, in an unavailable state.

Finding out what command a keyboard shortcut is bound to

Another “fun” way of learning about Visual Studio is to scroll through the list of commands available.  For example, if you type Edit.Line, you’ll see all of the commands that contain “Edit.Line”.  You’ll discover a command called “Edit.LineTranspose” which is bound to Shift+Alt+T.  In case you ever need to transpose a line, you now know the keyboard shortcut for it. =)

Technorati tags: VS2005Tip, VS2008Tip