Udostępnij za pośrednictwem


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+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:

  • Navigation bar

  • Bookmarks in the Bookmarks Window

  • Comment tasks in the Task List

  • Incremental searches

  • Go to Linecommand

  • Go to Definitioncommand

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.

Note

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 Nameand 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.

To edit a document elsewhere and then return to your current location, add a bookmark to the Bookmark Window.

To add a bookmark

  1. In the Editor, select a line you want to return to at a later time.

  2. In the Bookmarks window, click the Toggle Bookmark button

    Add Bookmark Button

    A bookmark symbol

    Temporary 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

    Next Bookmark Button

    or Previous Bookmark

    VisualBasicWinAppProjectPreviousBookmarkButton scr

    -or-

  • 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.

    Tip

    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

    VisualBasicWindAppProjectRemoveAllBookmarksButton

    —or—

  • Press CTRL+K and then CTRL+L to erase all bookmarks from the active document.

    Note

    To delete a single bookmark, right-click the bookmark and click Toggle Bookmark, or keep pressing CTRL+K until the bookmark is removed.

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

  1. 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.

  2. Continue working in the document.

  3. In the View drop-down list on the Task List toolbar, select Comments.

    Any comments in the code of the active document are displayed.

  4. 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.

  1. Select Advanced on the Edit menu and choose Incremental Search.

  2. 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

  1. In the General, All Languages, Text Editor, Options Dialog Box, select the Line Numbers option.

  2. With a document open in the Editor, select Go to Line from the Edit menu.

  3. 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

  1. Select any call to a procedure or variable.

  2. Press F12.

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 Code and Components.

See Also

Tasks

How to: Go To a Line of Code

How to: Bookmark Code

How to: Create Task List Comments

Reference

Class View and Object Browser Icons

Other Resources

Finding and Replacing

Setting Bookmarks in Code

Editing Text, Code, and Markup