How to: Navigate Code and Text
There are various ways to move through text or code in the Code Editor using the mouse and navigation keys:
Use the arrow keys to move one character at a time, or the arrow keys in combination with the CTRL key to move one word at a time. Arrow keys move one line at a time also.
Click a location with the mouse.
Use the scroll bars or scroll wheel on the mouse to move through the text.
Use the HOME, END, PAGEUP, and PAGEDOWN keys.
Use CTRL+PAGE UP and CTRL+PAGE DOWN to move the insertion point to the top or bottom of the window, respectively.
Use CTRL+HOME and CTRL+END to move the insertion point to the start or end of the file, respectively.
Use CTRL+UP ARROW and CTRL+DOWN ARROW to scroll the view without moving the insertion point.
Use the Navigate Backward button to move the insertion point to previous locations in the active document, and the Navigate Forward button to return to more recent locations.
Operations such as Incremental Search, Goto Line, Goto Definition, Beginning of Document, End of Document, Paste, and Insert File can move the insertion point a significant distance within the active document. The Navigate Backward and Navigate Forward buttons retain the last 20 locations of the insertion point.
The following sections describe other ways to move to specific sections and lines of code:
Bookmarks in the Bookmarks Window
Comment tasks in the Task List
Go to Line command
Go to Definition command
Navigating with the Navigation bar
The Navigation bar consists of two combo boxes displayed at the top of the Code Editor. It allows you to navigate directly to a particular class or type, or to a procedure or member within it. Not every project incorporates the Navigation bar.
The names of the two combo boxes on the Navigation bar vary depending on the type of project. For example, in Visual Basic projects, the boxes are named Class Name and Method Name. In C# projects, the boxes are named Types and Members.
To shift focus from the Code Editor to the Navigation bar
- Press the shortcut key combination CTRL+F2.
To return focus from the Navigation bar to the Code Editor
- Press the ESC key.
To shift focus from item to item on the Navigation bar
- Press the TAB key.
To select the Navigation bar item that has focus and return to the IDE
- Press the ENTER key.
To navigate to a class or type
- Click its name in the Class Name/Types combo box in the upper left corner of the document.
To navigate directly to a procedure in a class
Click a procedure in the Method Name/Members combo box in the upper right corner of the document.
Note In a partial class, members defined outside the current code file may be grayed out.
Navigating with Bookmarks
To edit a document elsewhere and then return to your current location, add a bookmark to the Bookmark Window.
To add a bookmark
In the Editor, select a line you want to return to at a later time.
In the Bookmarks window, click the Toggle Bookmark button
A bookmark symbol
is displayed in the left margin of the Editor to mark the line.
Keep pressing CTRL+K to toggle a bookmark on and off.
To move through bookmarks in the active document
In the Bookmarks window, click Next Bookmark
or Previous Bookmark
Press CTRL+K and then CTRL+N to move to the next bookmark, or CTRL+K and then CTRL+P to move to the previous bookmark.
Another way to return to a location is by using the Navigate Backward and Navigate Forward buttons.
To remove all bookmarks from a document
In the Bookmarks window, click the Clear Bookmarks button
Press CTRL+K and then CTRL+L to erase all bookmarks from the active document.
To delete a single bookmark, right-click the bookmark and click Toggle Bookmark, or keep pressing CTRL+K until the bookmark is removed.
Navigating with Comment Tasks
You can create comments tasks in your code that mark places to which you will need to return, and then navigate directly to those locations from the Task List.
To create and use a comment task
Add a comment to your code that begins with the comment marker for the language in which you are developing, followed immediately by a comment token. For example, in Visual Basic, enter a comment such as this:
'TODO: Complete this routine.
This task is automatically added to the Comments list in the Task List.
Continue working in the document.
In the View drop-down list on the Task List toolbar, select Comments.
Any comments in the code of the active document are displayed.
Click the comment task to return to its location in your code.
For more information, see Task List (Visual Studio).
Incremental search helps you navigate directly to locations in the current document as you enter the search characters.
To navigate using incremental search
Select Advanced on the Edit menu and choose Incremental Search.
Begin typing the characters of the string you wish to find.
As you add characters, the Editor highlights the first matches found in the current document.
Go to Line command
Use the Go to Line command to move the insertion point to a specific line number.
To go to a specific line number
In the General, All Languages, Text Editor, Options Dialog Box, select the Line Numbers option.
With a document open in the Editor, select Go to Line from the Edit menu.
Enter the line number you want to view.
Go to Definition command
Use the Go to Definition command to navigate to the procedure for a method or a variable definition. For example, if you define a procedure called MyProc(), and then later in your code make a call to MyProc(), you can navigate directly to the procedure for this method using Go to Definition.
To go to the definition for the procedure or variable called
Select any call to a procedure or variable.
You are taken to the definition for the procedure or variable. To return to the point of the call, press the Navigate Backward button.
If the definition lies outside your project, its source is displayed in the Object Browser. For further information, see Browsing Through Code and Components.