Skip to content
Tutorials Center
My learning

Topics

Lesson 13 of 40 ยท Editing and Navigation

Quick Open and Go To: Navigating Code

Move around large projects fast in VS Code: Quick Open with Ctrl+P, go to line and symbol, workspace symbols, definitions and references, peek, bookmarks and navigation history.

In a real project you spend more time moving between places in code than typing. VS Code offers a family of Go To commands that jump to a file, a line, a symbol, a definition or a reference without touching the mouse. This lesson shows each one and how they combine.

Quick Open (Ctrl+P)

Ctrl+P opens a box where you type part of a file name. It fuzzy-matches across the whole project, so usrctl finds UserController.php, and src/comp/btn finds src/components/Button.tsx. Files you opened recently are listed first.

While the list is open:

  • Enter opens the file; Ctrl+Enter opens it beside the current editor.
  • Ctrl+P again (pressed twice quickly) cycles through recently opened files; that is a quick "previous file" jump.
  • Add :42 to go to line 42: app.js:42. Add :42:10 for line and column.
  • Add @name to jump to a symbol in that file: app.js@init.
  • Press Esc to cancel.

By default a single press opens the file in a preview tab (italic), see The Workbench Layout. The search.exclude and files.exclude settings hide files from Quick Open too.

Go to line (Ctrl+G)

Ctrl+G asks for a line number; type it and press Enter. Typing 10:5 goes to line 10, column 5. Handy for jumping to an error line from a stack trace.

Go to symbol in file (Ctrl+Shift+O)

A symbol is a named thing in code: function, class, method, variable, heading in Markdown. Ctrl+Shift+O lists the symbols of the current file; type to filter, press Enter to jump. Type : after @ to group by kind: @: shows classes, functions and so on together.

The Outline view in the Explorer shows the same symbols as a tree, and the breadcrumbs above the editor show where the cursor is in that structure.

Go to symbol in workspace (Ctrl+T)

Ctrl+T searches symbols across the whole project: type parseDate and it lists every function or class with a matching name in any file. It relies on your language extension, so it works best when the language service has finished loading.

Go to definition and friends

When the cursor is on a name, these commands use the language service to find related code:

Command Shortcut
Go to Definition F12 (or Ctrl+Click)
Peek Definition Alt+F12
Go to Declaration (Command Palette)
Go to Type Definition (Command Palette)
Go to Implementations Ctrl+F12
Go to References Shift+F12
Peek References Shift+Alt+F12 (varies)
Find All References Shift+Alt+F12
Go Back / Forward Alt+Left / Alt+Right

Peek Definition opens the definition in a small inline window under the current line, so you can read and even edit it without leaving your place. Press Esc to close it. This is often better than a full jump, because you do not lose context.

Go to References (Shift+F12) lists every use of a function, and the references peek view lets you step through them with the arrow keys. This is the safe way to understand the impact of a change.

On a Markdown, CSS or HTML file the same commands work for links and class names when the language support is installed (for example Ctrl+Click on import './utils' opens that file).

VS Code remembers where your cursor was. Alt+Left goes back, Alt+Right goes forward (macOS: Ctrl+- and Ctrl+Shift+-). After following a definition through four files, tap Alt+Left four times to return. Ctrl+K Ctrl+Q returns to the last edit location, a good way to jump back to where you were typing.

Bookmarks and folding

  • Fold / unfold a block with Ctrl+Shift+[ and Ctrl+Shift+]. Ctrl+K Ctrl+0 folds everything; Ctrl+K Ctrl+J unfolds everything; Ctrl+K Ctrl+1 ... 7 folds to a given level.
  • Bookmarks are not built in, but the Bookmarks extension adds Ctrl+Alt+K to toggle one and Ctrl+Alt+L / Ctrl+Alt+J to move between them.
  • Sticky Scroll (editor.stickyScroll.enabled) pins the names of the enclosing function or class at the top while you scroll long code.
  • Ctrl+Shift+\ jumps to the matching bracket.

Tabs, groups and the file tree

  • Ctrl+Tab switches between open editors (hold Ctrl to see the list).
  • Ctrl+K Ctrl+E or Reveal in Explorer (Ctrl+K R) selects the open file in the Explorer tree.
  • Ctrl+Shift+E shows Explorer; type a letter in the tree to jump to a matching name.
  • Open Editors section shows all open tabs; the setting explorer.openEditors.visible controls how many.

A stand-in: how Quick Open picks a file

Quick Open's ranking is a fuzzy match on the file name first, then the path. Here is a simplified JavaScript model: it requires letters in order, prefers matches in the file name and at word boundaries, and lists recent files first for ties. It is not VS Code's code, but it behaves similarly enough to understand why typing less often works.

JS Stand-in: a mini Quick Open

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Habits for large projects

  1. Never click through the tree for a file you can name: use Ctrl+P.
  2. Prefer Peek over a full jump when you only need to read.
  3. Use Alt+Left liberally; it makes exploring free.
  4. Use Ctrl+T to find a class by name when you do not know the file.
  5. Keep the Outline open in a secondary side bar when reading long files.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does typing app.js:42 into Quick Open do?

    A colon and number after a file name opens the file at that line.
  2. 2. Which shortcut lists symbols in the current file?

    Ctrl+Shift+O is Go to Symbol in File; Ctrl+T searches the whole workspace.
  3. 3. What is the advantage of Peek Definition (Alt+F12)?

    Peek shows the definition in a small inline window, so you keep your context.
  4. 4. How do you return to the previous cursor location after following definitions?

    Alt+Left (Go Back) walks the navigation history; Alt+Right goes forward.

Summary

  • Ctrl+P opens files by fuzzy name; add :line or @symbol to jump inside the file.
  • Ctrl+G, Ctrl+Shift+O and Ctrl+T go to a line, a symbol in the file and a symbol in the workspace.
  • F12 goes to definition, Alt+F12 peeks, Shift+F12 lists references.
  • Alt+Left and Alt+Right move through navigation history.
  • Folding, Sticky Scroll and the Outline help you read long files.

Next: Snippets and Emmet