Saturday, March 28, 2009

A Few Visual Studio Shortcuts!

Alright, alright... Soon enough I'll get back to writing about C# proper, (or F# or Silverlight, or any number of the new things I've been delving into lately). Lately, I've also been on a productivity kick, and as part of that, I've been hunting down a few Visual Studio Keyboard shortcuts to use. Not exactly non-published or new material, but cool nonetheless. It never hurts to start weening yourself off the keyboard. Here's a few of my favorites:

Go to Solution Explorer - [Ctrl]+[Alt]+L
Go to Error List - [Ctrl]+\, E
Line Open Above - [Ctrl]+[Enter] - This (and it's brother below) are certainly among my top competitors for best shortcut. Certainly beats clicking [Up] [End] [Enter], which is what I was doing before.
Line Open Below - [Ctrl]+[Shift]+[Enter] - So I hate the "end" button, because it's too close to backspace on my laptop. This will add a new line below the current one and reposition the cursor for you. It doesn't matter if you're already in the center of the line, it will reposition the cursor for you.
Cut Line - [Ctrl]+L
Toggle Outlining - [Ctrl]+M, [Ctrl]+M - Okay, so this one, combined with cut line, is one of the most powerful ways of eliminating huge blocks of commented code. It's much better than highlighting and deleting. Just try it. Put your cursor in a block of commented out code, and try [Ctrl]+M, [Ctrl]+M, [Ctrl]+L. It'll delete the whole block in three keystrokes.
Select Word - [Ctrl]+W
Go To Navigation Bar - [Ctrl]+[F2]
Go To Definition - [F12] - I know I can right click, but this is much faster, IMHO. I like to combine this functionality with the next couple of shortcuts.
Navigate Backward - [Ctrl]+- - That's "control minus". Try this after Go To Definition. This is incredibly useful in N-Tier applications or anywhere where you're trying to trace a rabbit trail to it's end, and then decide you want to alter something at the front end.
Navigate Forward - [Ctrl]+[Shift]+- - "Control shift minus", the opposite of Navigate Backward.
Find All References - [Shift]+[F12] - This will find all references, and place focus on the Find Symbol Results window. If you want to revisit the Find Symbol Results, try:
Show Find Symbol Results - [Ctrl]+[Alt]+[F12]
Rebuild All - [Ctrl]+[Shift]+R
Add Breakpoint - [F9]

And my personal favorite:

Show Smart Tag - [Shift]+[Alt]+[F10] - What's a smart tag? The smart tag is that little elusive box that gives you options about how to refactor code in certain ways. It's the box that can be opened to add a using statement to the top of your code when you enter a class name that is in a namespace not already in your using statements. I've always found that opening this box can be a little elusive, as I have to hover my mouse over it just right to get the box to expand enough for me to click it. Definately saves time.

Write 'em down, remember 'em, and become a more efficient developer.