Understanding Commands: Simple Commands

Keyboard:  CTRL + ALT + A
Menu:  View -> Other Windows -> Command Window
Command:  View.CommandWindow
Versions:  2008,2010
Published:  8/8/2010
Code:  vstipTool0067

 

Just about everything you do in Visual Studio comes with an associated command.  But WHAT is a command?  According to the MSDN documentation commands "allow direct interaction with the integrated development environment (IDE) from the keyboard. Many dialog boxes, windows, and menu commands within the IDE have a command-line equivalent that you can" use.  In plain English, commands allow you to do stuff in Visual Studio.  Let's take an example:  Add Class.

 

First, let's examine the  typical way you add a class.  Normally, you would just go to Project -> Add Class:

image

 

Obviously, this command is used to add a new class to your project and shows the Add New Item dialog:

image

 

 

That's  too much extra work for something I like to use all the time.  I want to "search" to see if there is a command that is associated with this action.  I'll go to Tools -> Options -> Keyboard:

image

 

I'll type a keyword in the "Show commands containing" area to narrow down the command list.  In this case, the keywords "Add Class" are used in the menu item so I will use it here.  Notice how I remove the spaces for the command:

image

 

As you can see there is an Project.AddClass command.  It's common to find a command that follows the Menu structure and this command is no exception: 

image

 

Also notice there are no shortcuts associated with the command.  Why don't we add one?  For this example, I'll use CTRL + M, CTRL + 7 as the shortcut key to be assigned:

image

 

For now I won't get into the nuances of assigning shortcut keys but you can get the details at vstipTool0063.  Assuming the key was assigned correctly, we can click OK then press CTRL + M, CTRL + 7 to see the New Item dialog pop up:

image

 

 

It works!  Now you understand the power of commands.  They can be quite useful and, once you assign a shortcut key, you will see it in the menu as well:

image