Skip to content
Tutorials Center
My learning

Topics

Lesson 9 of 40 ยท Interface and Settings

Keyboard Shortcuts and keybindings.json

Learn the essential VS Code keyboard shortcuts, search and rebind them in the Keyboard Shortcuts editor, write keybindings.json entries with when clauses and avoid conflicts.

Keyboard shortcuts are where VS Code starts to feel fast. This lesson lists the essential ones, shows how to find a shortcut for any command, and teaches the keybindings.json format for creating your own. Shortcuts here are for Windows and Linux; on macOS replace Ctrl with Cmd and Alt with Option in most cases.

The essentials

Action Shortcut
Command Palette Ctrl+Shift+P
Quick Open file Ctrl+P
Settings Ctrl+,
Toggle Side Bar / Panel Ctrl+B / Ctrl+J
Toggle terminal Ctrl+`
Save / Save All Ctrl+S / Ctrl+K S
Close tab Ctrl+W
Split editor Ctrl+\
Find / Replace Ctrl+F / Ctrl+H
Search in files Ctrl+Shift+F
Go to line Ctrl+G
Comment line Ctrl+/
Move line up / down Alt+Up / Alt+Down
Copy line up / down Shift+Alt+Up / Down
Delete line Ctrl+Shift+K
Undo / Redo Ctrl+Z / Ctrl+Y (or Ctrl+Shift+Z)
Format document Shift+Alt+F
Quick fix Ctrl+.
Go to definition F12
Rename symbol F2

Do not try to memorize all of them. Pick three new ones a week and use them until they become automatic.

Printable reference and the built-in cheat sheet

Help > Keyboard Shortcuts Reference opens a PDF cheat sheet for your platform. The Command Palette displays a shortcut next to each command, so you can also learn as you go.

Chords

Some shortcuts are chords: two key combinations in a row. Ctrl+K Ctrl+S means hold Ctrl, press K, release, then hold Ctrl and press S. After the first part the status bar shows (Ctrl+K) was pressed. Waiting for second key of chord.... Chords exist because there are not enough single combinations for the hundreds of commands.

The Keyboard Shortcuts editor

Open it with Ctrl+K Ctrl+S. It lists every command with its current shortcut and the when condition under which it applies.

  • Type in the search box to filter by command name, or by key: click the keyboard icon (Record Keys) and press a combination to see what it does.
  • Double-click a row, or click the pencil, to change the keybinding: press the new keys and Enter.
  • Right-click for Reset Keybinding, Remove Keybinding, Copy Command ID and Show Same Keybindings (to find conflicts).

When two commands share a shortcut, VS Code uses the one whose when condition matches the current context, and the user's entries win over defaults.

keybindings.json

Open it from the editor's top-right icon, or with Preferences: Open Keyboard Shortcuts (JSON). It is a JSONC array of objects:

JSON
[
  {
    "key": "ctrl+shift+d",
    "command": "editor.action.copyLinesDownAction",
    "when": "editorTextFocus && !editorReadonly"
  },
  {
    "key": "ctrl+alt+t",
    "command": "workbench.action.terminal.toggleTerminal"
  },
  {
    "key": "ctrl+k ctrl+1",
    "command": "-workbench.action.focusFirstEditorGroup"
  }
]

Each entry has:

  • key: lowercase modifiers joined by + (ctrl, shift, alt, cmd/meta/win), a chord separated by a space.
  • command: the command ID. A leading - removes that default binding.
  • when: an optional context expression deciding when the binding is active.
  • args: optional arguments passed to the command.

Command IDs appear in the Command Palette tooltips and in Copy Command ID. A command with arguments:

JSON
{
  "key": "ctrl+alt+j",
  "command": "workbench.action.terminal.sendSequence",
  "args": { "text": "npm test\n" }
}

That binding types npm test and Enter into the terminal.

When clauses

A when expression is a boolean made from context keys. Common ones:

Context key True when
editorTextFocus The cursor is in a text editor
editorHasSelection Text is selected
editorLangId == python The file is Python
terminalFocus The terminal has focus
inDebugMode A debug session is running
sideBarVisible The Side Bar is shown
resourceExtname == .md The file is Markdown

Operators: && (and), || (or), ! (not), ==, !=, =~ (regex). Developer: Inspect Context Keys lets you click an element and see its keys.

A stand-in: evaluating bindings

This JavaScript model chooses a command for a key press from a list of bindings and a context object. Real VS Code supports many more operators; this keeps &&, ! and == to show how when selects between two bindings on the same key.

JS Stand-in: resolving a key press

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

No output.

Keymap extensions

If you come from another editor, install a keymap extension such as Vim, Sublime Text Keymap, IntelliJ IDEA Keybindings or Atom Keymap. Preferences: Keymaps shows popular ones. They replace or add bindings, and your own keybindings.json still has priority.

Avoiding conflicts

  • Check the shortcut with Show Same Keybindings before reassigning.
  • Do not override keys your operating system uses (Alt+Tab, Win+L).
  • International keyboards: the key is a layout-dependent name; the setting keyboard.dispatch can switch to physical key codes, which helps on non-US layouts.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. How do you open the Keyboard Shortcuts editor?

    Ctrl+K Ctrl+S is a chord that opens the Keyboard Shortcuts editor.
  2. 2. What does a minus sign before a command in keybindings.json do?

    A leading - removes the matching default binding.
  3. 3. What is the purpose of a when clause?

    when clauses use context keys to decide whether a binding is active at the moment.
  4. 4. What is a chord?

    A chord such as Ctrl+K Ctrl+S is a sequence of two combinations.

Summary

  • Learn a few shortcuts at a time; the Command Palette shows the shortcut beside each command.
  • Ctrl+K Ctrl+S opens the Keyboard Shortcuts editor, where you search by command or by key.
  • keybindings.json entries use key, command, optional when and args.
  • A leading - on a command removes a default binding.
  • when clauses use context keys to avoid conflicts; keymap extensions import habits from other editors.

Next: Themes, Fonts and Icons