A few months ago when Bill Gates was on the Daily Show, Jon Stewart asked him a particularly insightful software question:
“So…what does the F12 button do? Does it do anything? Is it a joke button”. To which Bill replied jokingly – “I’d stay away from it if I were you.”
If you use Visual Studio though – I recommend you ignore Bill’s advice here. F12 is a quite useful keyboard shortcut.
Go To Definition
F12 itself invokes the “Go To Definition” (GTD) command. This works on types, members, locals, range variables, etc. It uses all the compiler’s internal understanding of the code to make sure it takes you to the right member – even when there are many overloads or if your code is using a lot of type inference.
Metadata As Source
One of the additions to “Go To Definition” support in Visual Studio 2005 was something we call “Metadata as Source”. If you go to definition on a type which is defined in a referenced assembly – you will be presented with a “header file”-style view of the corresponding type and it’s members. This keeps you in the editor – and gives a convenient view of the type. You can continue to navigate other members/types directly from the Metadata As Source view by using GTD again on those tokens.
Backward and Forward navigation
If you use GTD a lot, you’ll probably find yourself wanting to go “back” to where you invoked “go to definition” from. It turns out there is a keybinding for this:
- ctrl-shift-8: Takes you back in the GTD stack, to the the last place you invoked GTD
- ctrl-shift-7: Takes you forward in the GTD stack, to the last place you invoked back
Code Definition Window
The Code Definition Window is toolwindow which shows a live GTD of whatever symbol is currently under the cursor in the editor. If you find yourself using GTD a lot, you may want to pop up the Code Definition Window with ctrl-w-d.
BTW – If you are looking for more useful keyboard shortcuts using the C# Profile in Visual Studio – take a look at the C# keybinding posters Karen blogged about a little while ago.