次の方法で共有


Visual Studio 2013 Preview: Peek Definition aka Go To Definition (Peek)

Traditionally when you want to view the definition of a method you place your cursor inside the call:

5-16-2012 12-26-10 PM

 

Then press F12 to go to the document where the definition exists:

5-16-2012 12-27-17 PM

 

 

Using Peek

But what if you don’t want to leave your current location:

5-16-2012 12-26-10 PM

 

No problem! Just take advantage of the new Peek Definition feature by pressing ALT+F12:

5-16-2012 12-29-03 PM

 

This feature will actually open a small window below the method call so you can view its definition. This makes it very easy to view a definition without losing your place in the current document.

 

 

If I want to go to another definition from here I can just place my cursor inside the item:

5-16-2012 2-25-33 PM

 

And press ALT+F12 again. It will update the window to show the new definition:

5-16-2012 2-27-51 PM

 

But something else also happens. Notice the dots showing up in the top right-hand side of the window:

5-16-2012 2-29-46 PM

 

The Peek window is keeping track of the definitions you have been to so you can navigate easily between them:

5-16-2012 2-31-06 PM

 

You can use your mouse to click any of the dots or the forward and back links. Also, as you can see, you can use CTRL+ALT+Minus(-) and CTRL+ALT+Plus(+) to move backward and forward respectively.

 

I’m not sure what the upper limit is on number of entries it will remember but at 18 entries the More indicators showed up to allow navigating through a higher number of definitions. I suspect the number of entries can go quite high:

5-16-2012 2-42-08 PM

 

Finally

The next most obvious question is: “Can I edit the code in this definition window?” Currently the answer is “no” however it is something that is being considered before we ship. Let me know your thoughts.

Comments

  • Anonymous
    July 10, 2013
    How about a "Go to Implementation" option as well as "Go to Definition". In 90% of the time when using interfaces that is what the developer really wants.

  • Anonymous
    July 10, 2013
    +1 on what Craig has suggested.  That is the biggest reason why I may opt to buy Resharper.  However, I don't want to pay that hefty price.  

  • Anonymous
    July 15, 2013
    I agree, it needs Go to Implementation as well as Go to Definition.  In our code base, that's about 70% of our code navigation.  You also need to add support for editing, at least if you want to be competitive with Adobe Edge Code / Brackets.

  • Anonymous
    July 16, 2013
    +1 for "Go to Implementation". This is one of the features I miss the most when not using ReSharper (or similar). Also the "Move this class/enum/struct to its own file" feature but that's another story.

  • Anonymous
    July 24, 2013
    +1 for "Go to Implementation". With our MVP pattern we are doing a lot of work against interfaces, which means that quite often going to definition actually takes us to a method in an interface. Unfortunatelly command "Go to Definition" is completely useless for us.

  • Anonymous
    September 09, 2013
    +1 on what Oran said which would also include adding support for frontend code (css, javascript)

  • Anonymous
    September 12, 2013
    Oran, in VS 2013 RC Peek Definition is now fully editable.

  • Anonymous
    September 12, 2013
    I can confirm what Oleg and am happy for the change. By the way, I submitted the "Go To Implementation" idea to the team that owns this feature and here is the reply: "On the Go To Implementation feature, you are right – it would be a super cool feature to have!  Have you heard of the Roslyn project? The C#/ VB Languages team is working on a vNext project called Roslyn which enables exactly the capabilities such as Go To Implementation. We will certainly consider adding this feature. I will pass on your feedback to the languages team." The Roslyn project is actually public knowledge and you can go here to find out more: msdn.microsoft.com/.../roslyn.aspx Z

  • Anonymous
    November 16, 2013
    Is there a keyboard shortcut to close the navigation window (and all associated breadcrumbs)? Having a keyboard shortcut to get to something and then having to switch over to the mouse to get rid of it is a bit of a pain.

  • Anonymous
    November 18, 2013
    Mike, try pressing 'esc', works for me :)