F12 - Go To Definition

F12 - Go To Definition

Rate This
  • Comments 17

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.

Leave a Comment
  • Please add 7 and 6 and type the answer here:
  • Post
  • 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.

  • 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.

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

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

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

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

  • 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.

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

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

  • vb.net 2008

    f12: go to definition

    ctrl+shft+f12 returns to prior location

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

  • 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.

  • Any idea how to give GTD a source path so it would show the source code instead of metadata?  I can't find that information in MSDN.


  • Ken - There is not currently any way to point GTD at a source directory to use that instead of metadata.  The choice of which to use is based just on whether you have an assembly reference or project reference.  If you'd like to see a future version of Visual Studio support this, consider opening a suggestion at https://connect.microsoft.com/VisualStudio.

  • I used visual studio 2008,It does not work for me,but,i change the options after, it work find.

    Tool--Options--Environment--Keyboard--Apply the following additonal keyboard mapping scheme:--default --OK

    have a good lucky.

Page 1 of 2 (17 items) 12