Search and code navigation

VS Code · Essentials · 10 min

Reading and understanding code is mostly navigation; doing it by keyboard keeps you in flow.

Search across files with Ctrl+Shift+F. The search box supports match case, whole word and regex toggles, and the "..." toggle reveals files to include and files to exclude globs, such as src/**/*.ts or !**/*.test.ts. Files ignored by .gitignore and the search.exclude setting are skipped by default. Ctrl+Shift+H opens replace, previewing each change as a diff before you apply it; with regex on, $1 refers to capture groups.

Code navigation, powered by the language service:

  • F12 goes to definition, Ctrl+Click does the same with the mouse.
  • Alt+F12 peeks the definition inline without leaving your place.
  • Shift+F12 lists all references; Shift+Alt+F12 shows them in the References view.
  • Ctrl+Shift+O goes to a symbol in the file, Ctrl+T to a symbol in the workspace.
  • F8 jumps to the next error or warning.

After jumping, Alt+Left on Windows (Ctrl+- on macOS, Ctrl+Alt+- on Linux) goes back to where you were, and the matching forward shortcut returns, like a browser. The breadcrumbs bar above the editor shows the file path and symbol path; click any part to navigate siblings.

Ctrl+F and Ctrl+H are find and replace in the current file, with the same regex support.

Example

# Ctrl+Shift+F   search in files
#   query:       TODO|FIXME          (regex enabled)
#   include:     src/**/*.ts
#   exclude:     **/*.test.ts
# Ctrl+Shift+H   replace in files
#   find:        console\.log\((.*)\)
#   replace:     logger.debug($1)
# F12            go to definition     Alt+F12   peek definition
# Shift+F12      find references      Ctrl+T    workspace symbol
# Alt+Left       navigate back        F8        next problem

Remember

  • Ctrl+Shift+F with regex and include/exclude globs
  • F12 definition, Alt+F12 peek, Shift+F12 references
  • Navigate back after a jump; F8 cycles problems

Watch out for

  • Wondering why a file is missing from search results; it may be excluded by .gitignore or search.exclude.

Check yourself

  1. Which shortcut shows a definition inline without leaving the current file?

Sign in to answer, see the explanations, and get this lesson back as a quick review later.

Official docs: code.visualstudio.com/docs/editing/editingevolved

Builds on

Unlocks

Nothing builds on this yet.