Visual Studio Shortcuts
Here are some of the Visual Studio shortcuts I use.
Visual Studio includes a basic command-line prompt that is very useful for opening files. One way to enter commands is to press control+/, and then type >. You can then start typing a command, like "open", and then part of a filename. The nice part is that this autocompletes, so this is a great way to open any file in your solution quickly. Press enter and the command is run. All of the commands you see in Tools-Options-Keyboard can be entered too, such as "File.CloseSolution" and so on.
There is a "command window" that is dedicated to this. I've mapped Ctrl+Space to View.CommandWindow, which is quicker than Ctrl+/, >. You can set up an alias to any command. For example, to set up an alias to a commonly used file, enter this:
alias m File.OpenFile CommonlyUsedFile.cs
Now, you can press Ctrl+Space,m,Enter to quickly open that file - very useful if you have a large solution. There are many built-in aliases such as "open" for "File.OpenFile". View this list by typing "alias" with no parameters, or remove an alias with the syntax "alias m /delete". I deleted most of the other aliases, as I'd rather type Ctrl+F4 then "close", and so on.
Macros are a great idea, but I'm not too impressed with them in VS. VB is such an ugly language, and there is a distracting pause when running a macro. Anyways, I'd thought I'd try my hand. Here's something that will complete all nested parens and end the line. For example, if you type Console.WriteLine(a.ToString( and run the macro, it will add "));" and start the next line. I've mapped this to Control+Enter, and it can be useful if you are too lazy to count how many parens to close.
Dim line As String
line = DTE.ActiveDocument.Selection.Text
Dim nparens As Integer, i As Long
nparens = 0
For i = 1 To Len(line) - 1 Step 1
If StrComp("(", Mid$(line, i, 1), vbTextCompare) = 0 Then
nparens = nparens + 1
ElseIf StrComp(")", Mid$(line, i, 1), vbTextCompare) = 0 Then
nparens = nparens - 1
Dim strResult As String
strResult = ""
For i = 1 To nparens Step 1
strResult &= ")"
strResult &= ";"
DTE.ActiveDocument.Selection.Text = strResult.ToString()
I also have a macro that duplicates the current line, but I'm frustrated by the pause. My wish is to come up with something that could organize my Ctrl-Tab into visual, and not MRU order, but that's a story for another day.
Snippits are a great feature of VS 2005. You can easily create your own snippits by creating xml files. There is a nice GUI for creating Snippits called Snippy (A Visual Studio 2005 PowerToy), but it seems to have dissapeared entirely along with gotdotnet.com. So, I've posted it here (378k).
I wrote snippits for creating unit tests, switch statements, and some XAML structures. Most often I used prop and propd for quickly creating properties.
Finally, here are some keyboard bindings that I find useful:
Toggle Word wrap
If you happen to have MbUnit (which is cool) or VisualSVN,
MbUnit – Run Tests
VisualSVN-Revert Changes current item
VisualSVN- Show current file changes
VisualSVN – Show All Changes
Some of these override standard key bindings, but it’s easy to assign another. I have Ctrl+Shift+Space to be Edit.CompleteWord rather than Ctrl+Space. Anyways, those are some ways to make Visual Studio work for you. The Clipboard ring is nice also.