When developing applications in Visual Studio I work with the keyboard most of the time. Throughout the years I learned a lot of short cuts to a lot of features. I’m sure most of you know and use these, too. But there are some features or actions that do not work well with the keyboard. For example closing all open tabs or opening the TFS source control explorer. For actions like this I had to use the mouse, just because it was faster than the keyboard. Until I learned about this feature a while ago.
A couple of versions of Visual Studio ago there was a search box inside the toolbar. This search box can double as a command line. If you are using one of the latest versions of VS the search box is still there, but you’ll have to add it to your toolbar yourself. You can do this by clicking on the little triangle at the end of the ‘standard’ toolbar. Then click ‘Add or Remove Buttons’ and select ‘Find’.
Now the search box is back on the toolbar.
Normally when you type in this box and hit enter you’ll search for the text you’ve typed. But… When you hit ‘Ctrl+/’ on your keyboard the search box gets focus and a ‘ > ‘ is placed in there. Now you can enter commands to Visual Studio. For example, ‘>Window.CloseAllDocuments’ to close all open documents. When typing in this box you’ll notice you can a dropdownlist with completions for the command you’re typing. Because all of these commands a bit long to type you can add aliases for them. So in case of ‘Window.CloseAllDocuments’, I’d rather type ‘wca’. To accomplish this hit ‘Ctrl+/’ and type ‘alias wca window.CloseAllDocuments’. From now on you can type ‘wca’ to close all open documents.
Another command I use regularly is ‘tfs’ to access the TFS source control explorer. You can create this alias with ‘alias tfs Team.TfsSourceControl’.
One more thing I want to mention is that you can add ‘External Tools’ to the command aliases as well. One that I use is ‘cmd’ to open a command prompt at the root of my current selected project. I did this by first creating the ‘external tool’. You can open the window below by going to the tools menu and selecting external tools.
The values I entered are:
- Title: cmd
- Command: %windir%\system32\cmd.exe
- Arguments: “C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat”
- Initial directory: $(ProjectDir)
There are commands for 24 external tools that can be called in the search box. Mine happened to be the 6th. So I created an alias by typing ‘alias cmd Tools.ExternalCommand6´. From this moment on I can hit ‘Ctrl+/’ and type ‘cmd’ to open a command prompt at the root of my current project. Which I find very useful when working with NPM and Bower.
Let me know in the comments below what commands you are using in this command line.