Welcome to MSDN Blogs Sign in | Join | Help

F12 - Go To Definition

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.

Published Monday, June 04, 2007 11:14 AM by LukeH

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: F12 - Go To Definition

Monday, June 04, 2007 5:01 PM by evarlast

Thanks tons for this!

I use F12 a lot, but I typically use ctrl-minus to go to last position. I did not know about ctrl-shift-7 and 8. I'll have to try those out.

I think F12 and ctrl-minus are two HUGE productivity keystrokes for developers.

# re: F12 - Go To Definition

Tuesday, June 05, 2007 3:05 AM by jstangroome

Been using F12 for a long time in Visual Studio but was disappointed after installing the highly recommended ReSharper that it hijacks F12 for it's own, less useful, purposes. One step forward, two steps back.

# Community Convergence XXVIII

Wednesday, June 20, 2007 5:39 PM by Charlie Calvert's Community Blog

Welcome to the XXVIII Community Convergence. In these posts I try to wrap up events that have occurred

# re: F12 - Go To Definition

Thursday, March 27, 2008 7:01 PM by Juan

Does not work for me, I get the error "cannot navigate to" any ideas

# re: F12 - Go To Definition

Friday, August 15, 2008 6:40 AM by haha_254

It does not work for me. Nothing happen when I try Ctrl-shift-7 or -8

# re: F12 - Go To Definition

Wednesday, October 15, 2008 11:23 AM by Abhijit

Thanks for the tip on how to "go back" from an F12.

# re: F12 - Go To Definition

Tuesday, December 30, 2008 10:52 AM by xyzq

I prefer Borland style like Go to Definition by Ctrl + Left button click. Its pretty practical to use.

It could be implemented in VS too, i miss it.

# re: F12 - Go To Definition

Monday, February 23, 2009 7:44 PM by Action Lyrics

Is there any way to make it skip the metadata and go straight to the code?

# re: F12 - Go To Definition

Friday, February 27, 2009 5:04 AM by sudhakar

Does not work for me, I get the error "cannot navigate to" any ideas

# re: F12 - Go To Definition

Friday, March 27, 2009 11:24 AM by Ken Jett

vb.net 2008

f12: go to definition

ctrl+shft+f12 returns to prior location

# re: F12 - Go To Definition

Wednesday, April 29, 2009 5:46 AM by xhanness

VS sucks - compare it to Eclipse - that is the best IDE

# re: F12 - Go To Definition

Sunday, May 03, 2009 7:23 AM by Interface Mirror

A Bunch of thanks for F12. I searched a lot for it in VS.NET itself ut finally I got it from your post.

Thank you again.

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker