Did you know... How to create or change Visual Studio keyboard shortcuts? - #016

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

Comments

  • Anonymous
    August 15, 2007
    PingBack from http://msdnrss.thecoderblogs.com/2007/08/16/

  • Anonymous
    August 16, 2007
    If you're into key binding, you may want to check this out: http://www.slickedit.com/gadgets/ It's got something called the Command Spy which shows you which command you're executing whenever you click on a menu item or toolbar button in Visual Studio.  It also shows the keyboard shortcut you can use to do that command.  It's a great way to learn your key bindings and define new ones for the things you do all the time.  And it's free.

  • Anonymous
    August 16, 2007
    Ah, it really is the simple things in life, isn't it? Use Ctrl+K, Ctrl+C to comment code and Ctrl

  • Anonymous
    August 18, 2007
    It's a great feature IF IT WORKED. The Press Shortcut Keys thing doesn't accept Back, Forward buttons on the keyboard not to mention the mouse. The weird thing is that if you import C# environment, the back/forward start working on a fixed, non reassignable way. But in the beta 2 something was broken and now the back/forward feature doesn't work always. Now if you happened to choose General settings on your first time of starting VS, you don't even know there's this back/forward feature there since it's only in the C# settings. So I have to use C# settings for my C++ work due to this. Not a big deal but gives a buggy feeling for the product.

  • Anonymous
    January 14, 2008
    Ah, it really is the simple things in life, isn't it? Use Ctrl+K, Ctrl+C to comment code and Ctrl+K,

  • Anonymous
    January 14, 2008
    There are four commands that involve converting spaces to tabs and tabs to spaces. Edit – Advanced -

  • Anonymous
    February 03, 2008
    Yesterday's tip re: closing a tool window via the keyboard made me triple-check my notes that I never

  • Anonymous
    February 06, 2008
    Hmm, interesting how I got myself onto a "F6" theme this week... In what seriously feels like

  • Anonymous
    February 10, 2008
    The output window has a drop down, as shown below, to move between various outputs views (or panes),

  • Anonymous
    March 03, 2008
    Today's tip was co-authored with a tip of the day reader.  The idea is you just want to press

  • Anonymous
    July 13, 2008
    スペースとタブを相互に変換するには、次の 4 つのコマンドがあります。 [編集] メニューの [詳細] の [選択行にタブを設定] : 選択した行の先頭の空白をタブに変換します。 [編集] メニューの

  • Anonymous
    July 13, 2008
    今日は、本当に簡単にできる操作をご紹介します。 コードをコメント化するには、 Ctrl + K 、 Ctrl + C キーを使用します。コードのコメントを解除するには、 Ctrl + K 、 Ctrl

  • Anonymous
    July 13, 2008
    Visual Studio シェルは大きな環境です。このチームに参加する前、私は 1 年ほど Visual J++ を使っていました。今では当然のように使いこなしている手法で、その当時知っていたらどれほど役に立っただろうと思うものを、皆さんにご紹介します。その

  • Anonymous
    July 27, 2008
    Оболочка Visual Studio - сложная система. Я это знаю, поскольку я использовала Visual J ++ каждый день

  • Anonymous
    July 27, 2008
    Оболочка Visual Studio - сложная система. Я это знаю, поскольку я использовала Visual J ++ каждый день

  • Anonymous
    November 28, 2008
    La shell di Visual Studio è un grande posto. Dovrei saperlo, da quando ho utilizzato Visual J# tutti

  • Anonymous
    April 07, 2009
    개발자를 포함한 컴퓨터를 많이 사용하는 사람에게 꼭 필요한 것이 단축키입니다. Visual Studio에서 키보드 단축키를 생성 혹은 변경하는 방법은 아래와 같습니다. 1. Visual

  • Anonymous
    April 09, 2009
    단축키에 연결할 수 있는 동작을 보려면 아래와 같이 합니다. 1. Visual Studio에서 메뉴 -> 도구 -> 옵션을 선택하고, 옵션 창이 나타나면 왼쪽에서 환경 ->