Skip to content
Tutorials Center
My learning

Topics

Lesson 4 of 40 ยท Getting Started

The Command Palette

Learn the VS Code Command Palette: open it with Ctrl+Shift+P, use prefixes for files, symbols and lines, see how fuzzy matching ranks results, and bind your own shortcuts.

If you learn only one thing in VS Code, learn the Command Palette. It is a search box that lists every command the editor and your extensions offer. Instead of hunting through menus or memorizing shortcuts, you type a few letters of what you want to do and press Enter.

Open it with Ctrl+Shift+P (Cmd+Shift+P on macOS), or press F1. A box appears at the top of the window, with a > already typed in it. The > means "search commands".

Your first commands

Open the palette and try typing:

  • theme โ†’ Preferences: Color Theme
  • sort lines โ†’ Sort Lines Ascending (works on the selected lines)
  • format โ†’ Format Document
  • reload โ†’ Developer: Reload Window, the standard cure for a confused editor
  • toggle word wrap โ†’ View: Toggle Word Wrap
  • shell command โ†’ the command that installs code on macOS

Each result shows the command's shortcut on the right if it has one. That is a gentle way to learn shortcuts: use the palette first, notice the shortcut, and start using it when you are ready.

The palette remembers your recently used commands and lists them first, so the commands you use most are one keystroke away.

One box, many modes

The same input field switches meaning according to the first character you type. This is the second big idea: Quick Open, symbol search and the palette are one control.

Prefix Mode Shortcut to open directly
(none) Go to file by name Ctrl+P
> Commands Ctrl+Shift+P
@ Symbols in this file Ctrl+Shift+O
@: Symbols grouped by category
# Symbols in the whole workspace Ctrl+T
: Go to line number Ctrl+G
? Show help for all prefixes
edt Open editors list

You can also combine them: app.js:120 opens app.js at line 120, and utils@parse jumps to a symbol called parse inside the matching file. These modes are covered in depth in Quick Open and Go To.

How fuzzy matching works

You do not have to type a command's exact name. The palette uses fuzzy matching: the letters you type must appear in order, but not next to each other. So fdoc finds Format Document, and tcs finds Toggle Comment Selection. Matches at word starts and consecutive letters rank higher.

Here is a stand-in that models this ranking. It is not VS Code's real algorithm, but it uses the same ideas: subsequence matching, a bonus for word starts and a bonus for letters that follow each other.

JS Stand-in: a fuzzy command search

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

No output.

Try changing the query list or adding commands. Notice how rw finds Reload Window because both letters start words.

Commands with arguments and sub-pickers

Many commands open a second list. Preferences: Color Theme shows the themes and previews each as you move the selection; Git: Checkout to... lists branches; Change Language Mode lists languages. Press Esc to cancel, and the preview reverts.

Commands that are not available in the current context are hidden. For example, Format Document only appears when a file is open, and Git commands appear only inside a repository.

Where extension commands appear

Every extension can add commands, and they are grouped by a prefix before a colon: Git:, Python:, Docker:, Live Share:. Typing the prefix first filters to one extension's commands, which is a quick way to see what a newly installed extension can do. Type Python and scroll to discover them.

Give any command a shortcut

Next to each result you can click the gear icon to open Keyboard Shortcuts filtered to that command and assign a key combination. The full workflow is in Keyboard Shortcuts.

Habits that pay off

  1. Press the palette first, memorize later. If you do not know the shortcut, use the palette and let the displayed shortcut teach you.
  2. Use Developer: Reload Window when an extension misbehaves; it restarts the extension host without losing your open files.
  3. Use Developer: Show Running Extensions to find a slow extension.
  4. Search commands by intent. Words like wrap, fold, indent, sort and case find most text commands.
  5. Press ? in an empty box to list the prefixes and remind yourself of the modes.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which shortcut opens the Command Palette on Windows and Linux?

    Ctrl+Shift+P (or F1) opens the Command Palette; Ctrl+P opens Quick Open for files.
  2. 2. What does typing @ at the start of the box do?

    The @ prefix switches the box to symbol search in the current file.
  3. 3. Which query would fuzzy matching likely resolve to Format Document?

    Fuzzy matching needs the typed letters to appear in order, and f then d-o-c fit Format Document at word starts.
  4. 4. Which command is the usual first fix for a misbehaving extension?

    Reloading the window restarts the extension host and usually clears temporary problems.

Summary

  • Ctrl+Shift+P (or F1) opens the Command Palette, a searchable list of every command.
  • Prefixes switch the same box to other modes: files, > commands, @ symbols, # workspace symbols, : line numbers.
  • Fuzzy matching only needs your letters to appear in order; word starts rank best.
  • Extension commands are grouped by a prefix such as Git: or Python:.
  • Use the palette to learn shortcuts and to reach rarely used commands.

Next: VS Code, Visual Studio and vscode.dev