Did you know… There’s is a Go To Definition navigation stack?! - #367
update 2 dec 2008: This feature originated in C++ over 10 years ago. My bad C++ folks for my earlier statements that it was only a C# feature.
I added the exclamation point, because I never knew this. It is amazing that I’m still finding out about IDE features! When does the madness end? But in all fairness, this is a specific C# IDE feature, as it relates to the Go To Definition Window. (Sorry VB folks to do this to you yet again.)
We know that Visual Studio has a navigation stack because of the Navigate Forward and Navigate Backward keyboard shortcuts. But apparently, and little did I know, that Visual Studio has a separate navigation stack to track cursor movement for Go To Definition calls (but only for C# code?)
Start off by doing a Go To Definition, and of course the cursor moves to the definition. Now to get back to where you were before, you can use CTRL+SHIFT+8.
And to return to the definition, press CTRL+SHIFT+7.
I’ll be honest here and share that it has taken me over 30 minutes to figure out how this navigation stack works. It wasn’t until I took the screenshot for the Ctrl+Shift+8 keyboard shortcut and realized the command name was “View.PopBrowseContext” that I began to understand what is going on.
Ctrl+Shift+7 will push definitions onto the stack and Ctrl+Shift+8 will pop them off. What was hard for me to get is that this navigation stack is really a “stack,” meaning that push=Go To Definition and pop=go to location the Go To Definition was called. In other words, if you do as many Ctrl+Shift+7 as possible until you run out of definitions (implying an empty stack) and then do a Ctrl+Shift+8 to do a Go To Definition, the stack will have only one definition on it. So your next Ctrl+Shift+7 will only have one place to visit.
Please correct me if I’m wrong but I think this is just a VS2008 feature.
Technorati Tags: VS2008Tip
Comments
Anonymous
November 28, 2008
Seems to work for me in VS2005, too! Keep up the great tips.Anonymous
November 28, 2008
The similar VB combination is Shift-F2 / Ctrl-Sift-F2 -AlexAnonymous
November 28, 2008
Well, at least it works for C#. However, I'm a little mad at the visual studio team. This feature should had been always there. I mean: visual basic 6 has it!!! (Go to definition - Last position) My guess is that someone in the visual studio team said: "Why would anyone want that, I mean, you have bookmarks, just put a bookmark before going to the definition!" But believe me, that's a feature I have missed since I started with Visual Studio 2003. And I'm a VB.NET developer, so I'm gonna keep missing it :( Thanks for the tip, anyway Sara. Sometimes I have to write programs in C#, so I'm gonna be happy for moments :)Anonymous
November 28, 2008
I've never tried to navigate forward to a Go To Definition in C++ (never knew that you could, actually...hehe), but you can navigate back multiple times. Each time you use Go To Definition, it seems to add it to the stack, and then you can go back once for each definition.Anonymous
November 28, 2008
Ho aggiunto un punto esclamativo perché questo non l’ho mai saputo. è incredibile che io trovi ancoraAnonymous
November 28, 2008
Ctrl + - and Ctrl + Shift + - do this in vb.net, at least they did in vs2005, just checked 2008 and it does something else :(Anonymous
November 30, 2008
I've been doing this in 2005 for years using the mouse forward and back buttons (after using the Go To Definition context click). Much quicker than a key combination.Anonymous
April 09, 2009
本篇包括tip361-tip370http://www.watch-life.net/visual-studio/visual-studio-2008-tip-day-36.html#361、按...