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.

Wednesday, March 18, 2009

On Visual Studio Settings again

About three weeks ago, I wrote a post on what to do if Visual Studio Settings don't hold.

Well, there were a couple of reasons for this post:

1. The settings didn't seem to hold.
2. If my Visual Studio window wasn't in the same place it was when I saved my settings, and I tried to change settings, I would often have Visual Studio just plain crash on me.

Well, about a week after I put out my post, Microsoft released a patch to fix the latter issue.

You can find it here:

Wednesday, March 11, 2009

Another Reason to Love the Watch Window

I feel like a kid in a candy store recently.

Have you ever been in one of those debugging situations where you want to check what the value of something in your code is, perhaps the result of a condition within an if statement? So you open up your watch window and type in the condition (or a portion of it) into the watch window to see what the result evaluates to.

Type no more, my friends. Next time, simply highlight the text in the tet editor that contains the statement you want to evaluate, then drag it to the watch window. The text you drag will be dropped into the watch window and immediately evaluated for you.

Just one more reason to love the watch window.

Friday, March 6, 2009

I Became a Believer of the Locals Window

I never used to use the Locals window in Visual Studio... I mean, why? Really, why? Doesn't the Watch window do exactly what I would want from the Locals window, plus allow me to keep track of other variables? So what's the big deal about the Locals window anyways?

Recently I changed my Visual Studio IDE Settings to a dual-screen model, and I decided to make the locals window a permanent fixture on my second screen. I've been using it occasionally, simply because it's easier and more stable than hovering over the field, property or variable and trusting in my mad mouse skills to prevent accidentally losing my place in the type hierarchy while checking a value. So yeah, it's a little useful I guess... if I have room.

Today, however, I "discovered" a nice new shortcut that has completely converted me to a believer in the Locals window. If I have both the Locals and the Watch window open, I can actually drag and drop variables from the Locals window to the Watch window. Call me a geek, but I think that's pretty cool. It'll even cast objects to the proper types, if you're, say looking at a variable where the declared type is a base class of the instantiated value held in the variable. Bonus. Thank you Locals window.