Welcome to MSDN Blogs Sign in | Join | Help

Sara Ford's WebLog


My adventures embracing open source on CodePlex and at Microsoft

News

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: ,
Posted: Thursday, August 16, 2007 3:00 AM by saraford

Comments

Scott Hackett said:

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.

# August 16, 2007 9:18 AM

Jason Haley said:

# August 16, 2007 10:28 AM

Noticias externas said:

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

# August 17, 2007 6:03 AM

Joku said:

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.

# August 18, 2007 8:51 AM

Sara Ford's WebLog said:

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

# January 15, 2008 12:28 AM

Sara Ford's WebLog said:

There are four commands that involve converting spaces to tabs and tabs to spaces. Edit – Advanced -

# January 15, 2008 12:30 AM

Noticias externas said:

Yesterday's tip re: closing a tool window via the keyboard made me triple-check my notes that I never

# February 4, 2008 6:27 AM

Noticias externas said:

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

# February 7, 2008 6:28 AM

Noticias externas said:

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

# February 11, 2008 6:44 AM

Noticias externas said:

Today's tip was co-authored with a tip of the day reader.  The idea is you just want to press

# March 4, 2008 6:50 AM

Visual Studio 2008 ワンポイント said:

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

# July 13, 2008 11:47 PM

Visual Studio 2008 ワンポイント said:

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

# July 13, 2008 11:49 PM

Visual Studio 2008 ワンポイント said:

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

# July 13, 2008 11:49 PM
New Comments to this post are disabled
Page view tracker