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.

View.PopBrowseContext command

And to return to the definition, press CTRL+SHIFT+7.

View.ForwardBrowseContext 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