CodeRush Tip – Enhance Standard VS Navigation

How many times have you hit Ctrl+Home or Ctrl+End (to navigate to the start or end of a file), only to realize mere seconds later, that you forgot to copy something to the clipboard before you left.

Now you have to find where you were, copy the code you were after, and then jump back.

There are several ways to get back to where you were:

  • Remember some snippet of code in the vicinity of where you want to be, and use VS’s find window.
  • Remember the name of the method you were in, and navigate to it using Quick Navigation, then locate the code within the method.
  • Page Up or Down to the location of your code. Scanning whole pages of code as you go in case you miss it.
  • Reach for the mouse and use the vertical scrollbar. While many people don’t like the mouse, this does give finer grain control than Page Up and Down.
  • Remember the exact line you were on and use Goto line (Ctrl+G)
  • View.NavigateBackward (See alternatives section after summary)

Wouldn’t it be great if you’d already dropped a CodeRush Marker before you left. That way you could just hit Esc and CodeRush would bring you back to where you were. It would even arrange the view the way it was before you left and restore the selection. Then you could copy the value you needed and return to whichever end of the file you wanted to.

Configuration

Actually setting this up is very simple. We’re going to use the exact same technique from when we Enhanced Studio's Find Command

  • Create a new shortcut (Details here)
  • Set key 1 to Ctrl+Home
  • Set command to MarkerDrop
  • Check the checkbox that says “after executing this command, pass shortcut to IDE for default handling
  • Set context to Focus\Documents\Source\Code Editor
  • Right Click this new shortcut
  • Select Duplicate Shortcut
  • Select the Duplicate
  • Change key 1 to Ctrl+End
  • Click Ok.

…and you’re done.

Summary

All you really need to understand having done this is that you can now visit the top or bottom of a file (via Ctrl+Home or Ctrl+End) and then easily revisit the location you came from, by hitting Esc.

Alternatives

There are those that will point to the built in visual studio View.NavigateBackward (Alt+Left) function. However this command is for me, somewhat less useful. It does not restore my view to how it was before. It does not restore the selection and it does not provide any kind of locator beacon to help me focus on where I was.

Now if only I could add CodeRush Markers to Notepad and Word Smile

3 comment(s)
Brad Schafbuch

Great idea to drop a marker on navigation commands, I had previously setup F12 (Go to Reference) to drop a marker and will be adding these too, thanks Rory!

15 June, 2011
Jay Wren

ctrl-minus navigates previous locations in VS by default, I think same as alt-left

awesome usage of "after executing this command let VS handle it too."

15 June, 2011
Rory Becker - DevExpress

@Brad: Indeed this should be useful in other navigational scenarios.

@Jay: It's all about 'embrace and extend' my friend.

Adding the icing to Visual Studio :)

15 June, 2011

Please login or register to post comments.