#90 Create a command alias

To create an alias, open up the Command Window (or anywhere you can type in VS commands) and type in something along the lines of

alias GobblesGobblesGobbles help.about

Command Window creating aliases

and now running GobblesGobblesGobbles from the VS command window will pop up the Help About menu.  I will award bonus points if you can figure out the Gobbles reference.  =)

But let’s explore a more practical application….

alias se View.SolutionExplorer

Now you can just type se to jump to the solution explorer.  For this particular example, the idea is you can be typing in the editor, press Ctrl+/ to jump to that Find window that can act as a command window, and type in se.

Actually, you’ve probably already used one of the predefined aliases before. Debug.Print is alias to ‘?’.  To see the full list of aliases, type in

alias

predefined aliases

Lastly, to reset your command window aliases back to defaults, type in

alias /reset

Reset aliases warning prompt

or just simply use the /delete switch to delete a particular alias, like alias se /delete.

 

#89 Run external executables from the VS command line

The command Tools.Shell will run an external executable out of process from VS.  To run, it is basically

Shell <executable>

But of course, we got optional arguments…

Shell [/commandwindow] [/dir:folder] [/outputwindow] <executable> [/args]

/commandwindow (or /c) – to display the executable’s output in the command window

/outputwindow (or /o) – to display the executable’s output in the output window

/dir:folder – specifics the working directory

For example,

Shell /o /c xcopy.exe c:\users\saraf\documents\cmdwinlog.txt c:\users\saraf\pictures

will display the xcopy output in the output window.

output redirected to the output window

#88 Log your command window session

You can record your command window session via the log command.  Just run

log -on <filename>

and start recording.  To finish logging, it’s just

log -off

There is also an option to overwrite the existing file; otherwise it will append.  Note that both dash and forward slash will work for command arguments. 

Command Window displaying logging commands

#87 Run Visual Studio commands with arguments from the command window

After the past several weeks of Find tips (i knew i would have a few tips, just not nearly a month’s worth!), let’s change things up a bit and talk about the command window.

Press Ctrl+Alt+A to open the command window.  Check the keybinding for View.CommandWindow if your keybindings are different.  Also available from the View – Other Windows – Command Window.  Now you can run various Visual Studio commands without having to go through the menus. 

Examples:

>File.Open c:\samples\foo.txt  //Open a file without going through the menu. 
>Help vs.commandwindow  //open a help topic directly
>? i  // get the contents of the variable i
>? i = 10  // set the contents of the variable i

View the following help topic for a list of commonly-used commands that include arguments in VS 2005.  Also available in VS 2008 documentation.

Auto-completion is also provided for both the commands and their corresponding arguments.

Command Window Auto-completion for commands

You can also get auto-completion for arguments. 

Command Window Autocomplete for Arguments

#86 browse Find Symbol results

The results of a Find Symbol or a Quick Find Symbol will appear in the Find Symbol results.  Similar to the Find Results window (when searching for text), you can

press Ctrl+Alt+F12 to bring up the Find Symbols Results window (View.FindSymbolResults)
press F8 (Edit.GoToNextLocation) to navigate to the next result, and Shift+F8 (Edit.GoToPreviousLocation) to navigate to the previous result
press F12 (Edit.GoToDefinition) within the Results window to jump to that symbol in the editor
bring up the context menu and select Browse Definition to view in the object browser.  This command is Edit.BrowseDefinition (in case you want to bind it to a keyboard shortcut)