Welcome to MSDN Blogs Sign in | Join | Help

Sara Ford's Weblog

My adventures embracing open source on CodePlex and at Microsoft

News

    • Did you know... All author proceeds go directly to sending Hurricane Katrina survivors to college.

      Microsoft Visual Studio Tips book

      Recent Entries

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.

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:
Posted: Friday, November 28, 2008 3:00 AM by saraford

Comments

Dr Herbie said:

Seems to work for me in VS2005, too!

Keep up the great tips.

# November 28, 2008 8:40 AM

priozersk said:

The similar VB combination is Shift-F2 / Ctrl-Sift-F2

-Alex

# November 28, 2008 8:47 AM

Antonio said:

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 :)

# November 28, 2008 9:31 AM

Andy said:

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.

# November 28, 2008 12:01 PM

Sara Ford's Tip of the Day - in Italiano said:

Ho aggiunto un punto esclamativo perché questo non l’ho mai saputo. è incredibile che io trovi ancora

# November 28, 2008 4:20 PM

Andy Davies said:

Ctrl + - and Ctrl + Shift + - do this in vb.net, at least they did in vs2005, just checked 2008 and it does something else :(

# November 29, 2008 5:21 AM

Chris Key said:

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.

# December 1, 2008 3:35 AM

xjb said:

# April 9, 2009 9:28 PM
New Comments to this post are disabled
Page view tracker