Navigate C++ code in Visual Studio (original) (raw)

Visual Studio provides a suite of tools that you can use to navigate around your codebase quickly and efficiently.

Open an included file

Right-click an #include directive, and select Go To Document. Or, select F12 with the cursor over that line to open the file.

Screenshot of the C plus plus Go To Document menu option in the context of some include statements.

You can switch between a header file and its corresponding source file. Right-click anywhere in your file and select Toggle Header/Code File. Or, you can select Ctrl+K, Ctrl+O.

Go To Definition/Declaration

You can navigate to the definition of a code element with a right-click in the editor and selecting Go To Definition, or by selecting F12. You can navigate to a declaration similarly by right-clicking to open the context menu, or by selecting Ctrl+F12.

Screenshot of options that appear when you right-click a code element. Includes Go To Definition, Peek Definition, and Go To Declaration.

Go To

Go To refers to a set of navigation features that each provide a specific result based on filters you specify.

You can open Go To with Ctrl+,. This action creates a search box over the document you're editing.

Screenshot of the search box that appears when you open Go To. There's a text box for your search terms, and filters for types, recent files, etc.

Go To includes these search filters:

When you first invoke Go To with Ctrl +, Go To All is activated (no filters on search results). You then can select the filter you want by using the buttons near the search box. You can invoke a specific filter using its corresponding keyboard shortcut. Doing so opens the Go To search box with that filter preselected. All keyboard shortcuts are configurable.

To apply a text filter, start your search query with the filter's corresponding character followed by a space. (Go To Line can optionally omit the space.) These text filters are available:

The following example shows results from a Go To Files operation by using the "f" filter:

Screenshot of Go to Files results. The user typed 'f str' and string_utils.cpp and string_utils.h appear because they contain str in the name.

To see the list of text filters, type a ? followed by a space. You also can access the Go To commands with the Edit menu. This is another way to remind yourself of the main Go To keyboard shortcuts.

Screenshot of the Go To menu which has options like Go To Line (Ctrl + G), Go to File (Ctrl + 1, Ctrl + F), and more.

Find or Find in Files

You can run a text search for anything in your solution with Find (Ctrl+F) or Find in Files (Ctrl+Shift+F).

Find can be scoped to a selection, the current document, all open documents, the current project, or the entire solution. You can use regular expressions and plain text. It also highlights all matches automatically in the IDE.

Screenshot of the Find dialog. The user has searched channel. Yellow highlights in the file show all the places Channel is found.

Find in Files is a more powerful version of Find that displays results in the Find Results window. You can search external code dependencies, filter by file types, and more.

Screenshot of the Find and Replace dialog. The Find in Files page is selected. Options are shown for matching case, the whole word, and so on.

You can organize Find in Files results in two windows. You can append results from multiple searches together. Select a result to go to that location in the file.

Screenshot showing a Find in Files search result listing files containing text that matches the search string and an excerpt of each match.

For more information, see Find in Files in the Visual Studio documentation.

Find All References

To find all usages of a symbol in your codebase, place the caret in or just after the symbol, right-click, and then select Find All References. You can filter, sort, or group results in many different ways. Results populate incrementally. They're classified as Reads or Writes to help you see what's in your solution as opposed to system headers or other libraries.

Screenshot of Find all references results which shows the line where the symbol was found, which file and project it is located in, and so on.

You can group results by the following categories:

Filter results

To filter results, hover over a column and select the filtering icon that pops up. You can filter results from the first column to hide things like string and comment references that you might not want to see.

Screenshot of filtering options. Includes Confirmed, Disconfirmed, In comment, and unprocessed. Each shows how many results apply to that category.

Sort results

You can sort results by any column by selecting that column. You can swap between ascending or descending order by selecting the column again.

You can navigate to the definition of a type in a file, or to type members, by using the Navigation Bar that's above the editor window.

Screenshot of the Navigation Bar above the editor window. It shows cryptlib > ChannelSwitch > ChannelMessageSeriesEnd().

See also