Searching and Navigating Code in Visual Studio 2010


Every developer knows that navigating code is vital to happy and productive coding. We’ve added several new features for code search and navigation in Visual Studio 2010, including Navigate To and an improved Call Hierarchy, to complement search staples like the Find and Replace dialog and Incremental Search. With such a wide variety of options, we thought it would help to describe many of VS 2010’s code search and navigation features, from old favorites to new additions, in one place:


Find and Replace


Find and Replace


The Find and Replace dialog provides your basic search functionality. It comes in three flavors:



  1. · Quick Find (Ctrl+F): Optimized for smaller searches, Quick Find is best for searching open documents for a string or expression. It also provides basic options for search scope, partial word matching, case sensitivity, searching up vs. down, and use of regular expressions or wildcards in searches.

· Find in Files (Ctrl+Shift+F): A more robust option, Find in Files is better for searching entire projects or solutions. Unlike Quick Find, Find in Files can list search results in the Find Results window and has additional options to specify which file extensions to search.


· Find Symbol (Alt+F12): Find Symbol allows you to search for symbols, including objects (namespaces, types, interfaces, enumerations, etc.) and members (classes, properties, methods, events, constants, variables, etc.).


Want to use the Find feature without the dialog?  Find Next (F3) will take you to the next occurrence of the text in the toolbar’s Find combo box, which is usually your most recent search term.  To start a new search, just select your desired text in the editor and use Find Next Selected (Ctrl+F3) to jump to the next occurrence of that text.


Incremental Search


Incremental Search


Incremental Search (Ctrl+I) is fast, lightweight, and interactive, allowing you to search for partial words and refine your search in real time. It uses very little screen real estate, doesn’t cover up your code, and is great for quickly finding a piece of code in your current file.


Navigate To


Navigate To


Navigate To (Ctrl+comma), new for Visual Studio 2010, is a powerful way to search, especially when you’re not sure exactly what you’re looking for. It helps you locate items in your code by using “fuzzy” search capabilities. For example, if you type Foo Bar instead of FooBar, Navigate To will still return useful results. It’s a smart, incremental search that refines as you type and will find any symbols (e.g. file, type, and member names) matching your search terms.


Call Hierarchy


Call Hierarchy


Call Hierarchy (Ctrl+ K, Ctrl+T), or right-click and choose “View Call Hierarchy”, helps you understand the flow of code execution in more complex solutions and projects (C# only). Invoking Call Hierarchy on a method, property, indexer, or constructor in the source code shows you a tree of all the calls to and from that method, property, etc. Each method, property, and constructor in the Calls To and Calls From nodes can also be expanded into its own Calls To and Calls From sub-nodes. Call Hierarchy is great for navigating by code path or understanding relationships between functions.


Go To Definition


Go To Definition


Go To Definition (F12) does what its name suggests: it takes you to the definition of a given symbol. It works for a variety of symbols, including methods, types, classes, members, and more. It’s great for diving into implementation details, especially when reading code.


Navigate Backward/Forward


Navigate Forward and Backward


Navigate Backward (Ctrl+minus) and Navigate Forward (Ctrl+Shift+minus) allow you to quickly move between places you’ve already been in your code. For example, say you just used Go To Definition and now you want to go back to where you came from. It’s easy – just use Navigate Backward. If you’re interested in exactly how this works or how we determine exactly where to navigate you back to, check out Sara Ford’s blog post for details.


Highlight References


Highlight References


Highlight References is another new feature in Visual Studio 2010 (C# and VB only). Any time you place the blinking caret on a symbol, Visual Studio will automatically highlight all instances of that symbol for you. So what does this have to do with navigation? You can actually cycle through these highlighted references – just use Ctrl+Shift+up arrow and Ctrl+Shift+down arrow to move to the previous or next highlighted symbol.


 


All of these are available in VS 2010 Beta1, so I’d encourage you to try them out, especially the new-for-VS 2010 Navigate To and Call Hierarchy features. Like what you see? Have suggestions for improvements? Want to share your favorite navigation tips & tricks? Please leave a comment and let us know!


Brittany Behrens
Program Manager, VS Platform Team

Comments (4)

  1. Go To Definition (F12), when the item is actually a method/function of an Interface, should allow the user to navigate to either the interface’s definition or an implementation of that interface.  If there’s more than one implementation, a list should show up.

    The same is true for partial classes: Go To Definition on a "partial" class should show both entries.

  2. It would be great to have a Firefox/Chrome-like quick find functionality. Right now Quick Find requires too much focus and takes too much place (intersects with the text you want to look at).

    Also, does anyone actually use "Search up" the way it is implemented in Notepad/VS? I mean, you have to always remember where the cursor is relative to where the expected results are (which you do not know in most cases).

  3. Nevermind, it seems incremental search is basically "Firefox/Chrome-like quick find".

  4. Ivan B says:

    The things I do most often in Visual Studio are probably CTRL+F and CTRL+G (Go to Line).  It looks like I might expand my toolset a little, now.  Incremental Search looks great.  Also, I always forget about Navigate Forwards/Backwards even though it would make my life a lot easier.  You should make those buttons bigger (maybe like the IE/Firefox forwards and backwards buttons?).