Search and Navigation Tips/Tricks with Visual Studio

This is the twenty-seventh in a series of blog posts I’m doing on the VS 2010 and .NET 4 release.

Today’s blog post continues on from the Debugging Tips post I did last week, and covers some useful searching and navigation tips/tricks you can take advantage of within Visual Studio.  These tips were ones that my friend Scott Cate (who has blogged dozens of great VS tips and tricks here) recently recommended to me as good tips that most developers using Visual Studio don’t seem to know about (even though most have been in the product for awhile). 

Hopefully this post will help you discover them if you aren’t already taking advantage of them.  They are all easy to learn, and can help save you a bunch of time.

Ctrl + i - Incremental Search

Most developers using Visual Studio are familiar with the “Find dialog” that you can launch by pressing the “Ctrl + F” key within the IDE.  A surprisingly large number of developers, though, aren’t familiar with the “Incremental Search” capability within Visual Studio. This enables you to search within your current document, and enables you to do so without having to bring up a dialog. 

Using Incremental Search

To enable incremental search, just type “Ctrl + i” within the editor.  This will subtly change your cursor, and cause your status bar at the bottom left of the IDE to change to “Incremental search: (search term)” – you can then type the search term you are searching for and the editor will search for it from the current source location you are on (no dialog required).

Below we did an incremental search for the term “action” and VS highlighted the first usage it found within the file:

image

We can then press “Ctrl + i” again to find the next usage of the same term (and continue this repeatedly):

image

Pressing “Ctrl + Shift + i” will reverse direction on the search, and allow us to skip backwards.

You can press the “Esc” key at any point to escape out of incremental search.  More details on incremental search can be found here.

F3 and Shift+F3 – Find Using Previous Search Term

One neat tip to know about incremental search is that after you press the ESC key to escape out of it, it will add the term you searched for to the find stack within the IDE.  The search term you used will show up within the “find” drop-down within the VS "standard toolbar:

image

You can always press the F3 key within Visual Studio to repeat the last performed search at a later point.  This is particularly useful for scenarios where you search for something, make a code change, and then want to continue from that point in the code.  Just press F3 and you’ll repeat the last search (in this case “action”) from that new point in the document – no need to re-type it.

Pressing “Shift + F3” will do a reverse search (from the current cursor location in the editor) of the last search term used.  You can easily toggle using F3/Shift+F3 to search forward and backwards within your document.

Ctrl + F3  - Find Using Current Selection

Another neat searching trick that you can use to avoid having to type your search term is to simply highlight a word (or part of a word) within the code editor, and then press “Ctrl + F3” to search for the next usage of it within the current file:

image

Pressing “Ctrl + F3” will search for the next instance of the text you have highlighted – allowing you to avoid having to type it:

image

Like before, you can use “Ctrl + Shift + F3” to perform a reverse search if you so choose, to search backwards within the document.

Ctrl + Shift + F – Find in Solution

Sometimes you want to search across your entire solution. 

“Ctrl + F” will bring up the find dialog and default it to search within the current document. “Shift + Ctrl + F” will bring up the find dialog and default it to instead search across the entire solution:

image

Doing a search like this will bring up the “Find Results” window within the IDE and allow you to navigate to each found instance of the term:

image

You can double-click each item in the “Find Results” window to navigate to that instance of the search term you searched for.

One tip a lot of people don’t know about is the ability to press “F8” or “Shift + F8” to navigate to the next/previous instance of that search term in the list.  This can make navigating through them much faster/easier, and avoid you having to use the mouse.

Shift + F12 - Find Usages

Most developers using Visual Studio know how to highlight a type and press F12 to “go to definition”.  This will bring up the definition of a class/type, and is a useful way to navigate to where it is defined.

Many developers don’t know about “Shift + F12” – which brings up all usages of a particular type.  This enables you to quickly see how a particular type is used.  To take advantage of it, simply select or move the cursor onto a type and press “Shift + F12”:

image

This will then bring up a “Find Symbol Results” window that list all usages of this type within the current solution:

image

Like with the previous tip, you can use “F8” and “Shift F8” to navigate forward/backward within each item within the list.

Ctrl + Minus and Shift + Ctrl + Minus - Navigate Backward/Forward

Have you ever navigated to a different code file, looked at something, and then wanted to navigate back to where you came from?  For example, you use F12 to “go to definition” and then want to return back to the code that used it?

A feature that a lot of people don’t know about in VS is the “Navigate Backwards” keystroke – “Ctrl + (minus key)”.  This will navigate to the previous document/location on the navigation stack.

To see this in action, try selecting a type in Visual Studio.  Below I’ve selected the “IController” interface:

image

Press F12 to navigate to the definition of it.  This opens up a new editor window with the source of the selected type:

image

Now to jump back to where we came from, press “Ctrl + (minus key)” and VS will take us back to where we were:

image

If you want to move forward in the navigation stack (which in this case would take us back to the IController.cs file), then press the “Shift + Ctrl + (minus key)”. 

Sara Ford has a good blog post that talks more about this feature, and explains the conditions when a new location is pushed onto the navigation stack. 

Ctrl + Alt + (down arrow) - Navigate to an Open File

Ever have a ton of files open within the IDE, and want an easy way to navigate between them? 

One useful key sequence you can use is “Ctrl + Alt + (down arrow)” – this will cause a drop-down to appear within VS that lists all open files within it:

image

You can use the arrow keys to select the file you want to navigate to – or better yet just start typing the file-name and Visual Studio will highlight it for you within the list.  For example, above I typed “Mo” and Visual Studio highlighted “ModelBinder.cs”.  Pressing the “enter” key will navigate me to that file:

image

This provides a nice, convenient, way to navigate between files without having to use the mouse or take your hands off the keyboard.  And remember that “Ctrl + (minus)” can be used to navigate you back to where you came from.

Navigate To, View Call Hierarchy, and Highlight References Features

Visual Studio 2010 brings with it a bunch of new code navigation and searching features – including the new “Navigate To” dialog, “View Call Hierarchy” feature and Highlighted References Feature.

image

I previously blogged about these three new VS 2010 features here.  If you haven’t already read this post and explored these capabilities, I highly recommend doing so – they are some great additions.

Other Editor Improvements

There are a ton of other code editor improvements in VS 2010 – many of them ones I’ve blogged about before.  Here are links to a few of my previous VS 2010 editor blog posts:

Also check out the other blog posts I’ve done in this VS 2010 and .NET 4 Improvements series.

Summary

Most of the above features have actually been in Visual Studio for several releases – but are ones that a surprising number of developers don’t know about.  Hopefully this blog post helps provide a convenient way to get started with them if you didn’t already know they existed.  If you need help remembering the keystrokes – print out a copy of the VS 2010 Keybindings Poster and keep it near your monitor.

To learn even more cool Visual Studio tips/tricks, subscribe to Scott Cate’s excellent Visual Studio Tips blog series (which is already up to 83 awesome tips and tricks).  Also subscribe to Sara Ford’s blog – she has an awesome set of tips/tricks that go back years. 

Hope this helps,

Scott

P.S. In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu

Published Tuesday, August 24, 2010 12:24 AM by ScottGu

Comments

# re: Search and Navigation Tips/Tricks with Visual Studio

Tuesday, August 24, 2010 3:42 AM by Masoud

That's grat,but what about unicode?is it supported?

# re: Search and Navigation Tips/Tricks with Visual Studio

Tuesday, August 24, 2010 3:43 AM by VAI

Did LINQtoSQL designer or EF designer have some search functions? Or, maybe there is a some extensions exists for searching table by name in designers?

# re: Search and Navigation Tips/Tricks with Visual Studio

Tuesday, August 24, 2010 4:01 AM by Thomas Levesque

Wow, I'm going to use Ctrl + F3 all the time, thanks for the tip ! (btw it seems to work in VS2008 too)

Regarding incremental search, it's quite handy but it has an annoying limitation: it doesn't search hidden text. Is there an option somewhere to change this behavior ?

# re: Search and Navigation Tips/Tricks with Visual Studio

Tuesday, August 24, 2010 4:29 AM by rlambda

Great Post.. I feel the ReSharper does the good job and reducing most of the development time. What you feel scott ?

# re: Search and Navigation Tips/Tricks with Visual Studio

Tuesday, August 24, 2010 4:32 AM by Eyal

Frankly, I never understood why Ctrl + Minus and Shift + Ctrl + Minus are used for navigation when the windows standard is ALT + LeftArrow and ALT + RightArrow. I always rebind these keys to navigate backard and forward but it's a pain when i'm working on someone else's computer..:)

# re: Search and Navigation Tips/Tricks with Visual Studio

Tuesday, August 24, 2010 4:46 AM by Miron Brezuleanu

There's also Ctrl-Shift-8 (C-*) that pops an item from the F12 "stack". For instance, if you do F12 then page down (or any other action that pushes another item on the go-back list), you'd need two Ctrl-Minus to go to the location where you pressed F12, but C-* will take you there directly.

This is very handy for Emacs and Vi veterans, which are used to their tag stacks and look for something similar in Visual Studio. Sadly, C-* is not mentioned often. Luckily, it is still present in Visual Studio 2010 :-)

# re: Search and Navigation Tips/Tricks with Visual Studio

Tuesday, August 24, 2010 5:00 AM by Steve Hobbs

Great post! Admittedly I didn't know about the incremental search feature, so thanks for pointing it out as it's pretty useful!

# re: Search and Navigation Tips/Tricks with Visual Studio

Tuesday, August 24, 2010 5:31 AM by Yair

I like the Ctrl + i - that's exactly what I was looking for!

# re: Search and Navigation Tips/Tricks with Visual Studio

Tuesday, August 24, 2010 6:45 AM by Soner Gonul

Nice post.

Thanks Scott..!

# re: Search and Navigation Tips/Tricks with Visual Studio

Tuesday, August 24, 2010 6:53 AM by Crispin

It would be useful if the "Find in Solution" results had a ghosted path to make identifying the file name a bit quicker. For my part I would like to see the file name first and in its own column.

# re: Search and Navigation Tips/Tricks with Visual Studio

Tuesday, August 24, 2010 7:24 AM by Damien

Thanks for these tips, some are pretty handy indeed! Sadly, there is one that does not work with French OS/keyboard: NavigateBackward. It seems to be assigned to Ctrl+·, which I cannot type on my keyboard (I need to type Alt+0183). I know I could reassign it, butI think all combinations with Ctrl are already assigned to something else and i don't to mess around too much with them. And it is strange that the shortcut does not work out of the box...

# re: Search and Navigation Tips/Tricks with Visual Studio

Tuesday, August 24, 2010 7:38 AM by kevmac

@Thomas Levesque,"I'm going to use Ctrl + F3 all the time, thanks for the tip ! (btw it seems to work in VS2008 too)"

FYI, it dates from the Visual C++ Developer Studio IDE, i.e., from at least VS 6 - probably there from earlier but that's when I first saw it used, by watching another developer! :)

I'm always discovering new tricks in VS!

But there are a few other tips in this post that I was unaware of and one I'd forgotten about.

# re: Search and Navigation Tips/Tricks with Visual Studio

Tuesday, August 24, 2010 7:53 AM by nsimeonov

With all these productivity tools available for Visual Studio it's amazing how little we have for MSSQL. In a day-to-day development I frequently need to lookup a table and usually faster to scroll up and down until I see it. Filtering is nice however the implementation is terrible. How about filtering as I type? 99.99999% of the time I'm searching for a table or stored procedure and this dialog box is just too awkward to use. And I don't think it's too different to implement.

I'm just thinking out loud...

# re: Search and Navigation Tips/Tricks with Visual Studio

Tuesday, August 24, 2010 1:31 PM by Mike

Pure awesomeness Scott.  I did not know all these shortcuts, but need them all the time!  Oh, and I also agree with the previous poster re searching sql tables currently is easiest scrolling up and down...it could use a little bit of your magic.  thx.

# re: Search and Navigation Tips/Tricks with Visual Studio

Tuesday, August 24, 2010 4:08 PM by Michael

Incremental Search is working as Alt + i for me in a VB.Net Environment

# re: Search and Navigation Tips/Tricks with Visual Studio

Tuesday, August 24, 2010 9:56 PM by Rodney Thomson

I got awfully excited when I saw the ctrl+i search mechanism!

Until I tried to use it.

- The area where the search text is 'entered' is not highlighted as an editable field. Thus it is all to easy to make a mistake in typing and not really notice because your eye is not drawn to the bottom left.

- Pasting from clipboard and/or defaulting to clipboard contents is not supported. Manually typing can produce more errors

The best search example in a graphical UI that I use on a regular basis is that in Firefox 3.6.

The workflow is this:

- ctrl-f (if not visible, makes the search taskbar visible) sets the focus to the search field.

- Hitting Enter will begin the search, with consecutive Enters finding the next search result. Shift+Enter goes in the reverse direction.

- and my favorite feature : "Highlight all" which highlights all matches in a horridly bright color allowing you to scan the entire document very quickly.

Now, maybe I have trained myself to use the Firefox search utility which is why I feel comfortable with it. But I do feel it is a good example of a non-intrusive inline search.

Or, we can all just use VI to edit :) VIemu anyone?

# re: Search and Navigation Tips/Tricks with Visual Studio

Wednesday, August 25, 2010 2:02 AM by sliderhouserules

The Ctrl + i thing is new, I'll have to try it out.

For SP1 can you have your devs make the search popup remember its settings? It's very glitchy with RTM here. Gets annoying.

# re: Search and Navigation Tips/Tricks with Visual Studio

Wednesday, August 25, 2010 9:41 AM by dsa1971

I used to use the Incremental Search a lot until I figured out it does not search hidden text.  I wish this limitation would be removed.  

# re: Search and Navigation Tips/Tricks with Visual Studio

Thursday, August 26, 2010 11:48 AM by DaTribe

Extremely useful to know these short-cuts. Definitely increases my productivity & fondness of visual studio.

# re: Search and Navigation Tips/Tricks with Visual Studio

Saturday, August 28, 2010 6:22 AM by Roger

Thanks for sharing this tips with us.

# re: Search and Navigation Tips/Tricks with Visual Studio

Saturday, August 28, 2010 7:53 AM by NoName

Instead of Ctrl + Alt + (down arrow) and then Enter I'm rather using Ctrl + Tab (so I think it's a mistake to shorten the file names in this window with dots).

Nice article, thx.

# re: Search and Navigation Tips/Tricks with Visual Studio

Sunday, August 29, 2010 12:01 PM by dennisgorelik

These are simple, though quite helpful VS.NET search tips.

I knew most of them, but didn't know about some others, such as:

<Ctrl><Shift><->

<F3> after <Ctrl><I>

Thanks!

# re: Search and Navigation Tips/Tricks with Visual Studio

Monday, August 30, 2010 2:33 PM by James Skemp

Turns out Ctrl + Alt + Down Arrow flips everything on my screen 180 degrees. Now that's odd ...

Otherwise, helpful tips.

# re: Search and Navigation Tips/Tricks with Visual Studio

Tuesday, August 31, 2010 6:17 AM by Softlion

> Thanks for these tips, some are pretty handy indeed! Sadly, there is one that does not work

> with French OS/keyboard: NavigateBackward. It seems to be assigned to Ctrl+·, which I cannot type on my keyboard (I need to type Alt+0183). I know I could reassign it, butI think all combinations with Ctrl are already assigned to something else and i don't to mess around too much with them. And it is strange that the shortcut does not work out of the box...

Confirmed. It never worked for me. Although CTRL+ (plus) never worked also. It used to on vs2008.

# re: Search and Navigation Tips/Tricks with Visual Studio

Tuesday, August 31, 2010 7:01 AM by akhilrajau

useful one.. backward and all always useful..

yes ctrl+alt+downarrow flis the screen

# re: Search and Navigation Tips/Tricks with Visual Studio

Tuesday, August 31, 2010 6:19 PM by John P

Searching within Hidden text is a must! How did that slip through the net? :)

# re: Search and Navigation Tips/Tricks with Visual Studio

Wednesday, September 1, 2010 4:14 AM by herzevekil

Thanks,

# re: Search and Navigation Tips/Tricks with Visual Studio

Tuesday, September 7, 2010 11:18 AM by John

Just so you know, When using the Ctrl+F3, you don't have to highlight what you want to search for.  If nothing is highlighted, the IDE will search for the word that the cursor is over.

# re: Search and Navigation Tips/Tricks with Visual Studio

Thursday, September 9, 2010 4:34 PM by Sumit Pranav

Interesting and impressive as always.

kudos.

# re: Search and Navigation Tips/Tricks with Visual Studio

Thursday, September 9, 2010 6:54 PM by tees

Why hasn't anyone told me about Ctrl + Shift + F before?! If you have any more of these please write another one of these because I didn't know about most of them and I feel like they could save me a ton of time.

# re: Search and Navigation Tips/Tricks with Visual Studio

Saturday, October 2, 2010 8:41 PM by mark mcgary

excellent information. I always forget some of the naviagation.