74 entries · 6 sections
VS Code keybindings.json Cheat Sheet
How to rebind anything in Visual Studio Code: the shape of a rule in keybindings.json, the key names and chord syntax the key field accepts, the when clauses that decide where a binding applies, and the command IDs worth pointing them at. For the default chords themselves, the VS Code shortcut list is the page you want.
Opening the keybindings file
| Syntax | What it does |
|---|---|
Ctrl+K Ctrl+S / Cmd+K Cmd+S | Open the Keyboard Shortcuts editor — the searchable table of every binding, default and custom. |
Preferences: Open Keyboard Shortcuts | The same editor from the Command Palette, when the chord is one you have not learned yet. |
Preferences: Open Keyboard Shortcuts (JSON) | Open your own keybindings.json. This is the file everything below is written in. |
Preferences: Open Default Keyboard Shortcuts (JSON) | The read-only list of every default rule, each with its command ID and when clause. Copy from here. |
workbench.action.openGlobalKeybindings | The command ID behind the Keyboard Shortcuts editor. |
workbench.action.openGlobalKeybindingsFile | The command ID behind Open Keyboard Shortcuts (JSON). |
workbench.action.openDefaultKeybindingsFile | The command ID behind the read-only defaults. |
%APPDATA%\Code\User\keybindings.json | Where the file lives on Windows, beside settings.json in the same User folder. |
~/Library/Application Support/Code/User/keybindings.json | The same folder on macOS. |
~/.config/Code/User/keybindings.json | And on Linux. VS Code only writes the file once you save a binding of your own. |
Developer: Toggle Keyboard Shortcuts Troubleshooting | Log every dispatched shortcut to the Output panel, so you can see what the editor actually received. |
The shape of a rule
| Syntax | What it does |
|---|---|
[ { ... }, { ... } ] | The whole file is one JSON array of rules. A trailing comma is the usual reason a file stops applying. |
// a comment | Comments are allowed — the file VS Code creates opens with one telling you what it is for. |
"key" | The keypress, or chord, that triggers the rule. |
"command" | The identifier of the command to run. |
"when" | Optional. A boolean expression over the current context. Without it the binding applies everywhere. |
"args" | Optional. An argument object handed to the command. |
"systemWide" | Optional boolean that registers the shortcut system-wide rather than only inside the editor. |
{ "key": "enter", "command": "type", "args": { "text": "Hello World" }, "when": "editorTextFocus" } | A complete rule using all four fields: type a fixed string wherever the cursor is. |
Writing the key field
| Syntax | What it does |
|---|---|
"ctrl+f" | One or more modifiers and a key, lower case, joined with +. |
"ctrl+k ctrl+c" | A chord — two separate keypresses, written with a space between them. |
ctrl+ shift+ alt+ cmd+ | The modifiers on macOS. |
ctrl+ shift+ alt+ win+ | The modifiers on Windows. |
ctrl+ shift+ alt+ meta+ | The modifiers on Linux. |
a-z and 0-9 | Letter and digit keys. |
f1-f19 | The function keys. |
left up right down pageup pagedown end home | Navigation keys. |
tab enter escape space backspace delete | Editing keys. |
pausebreak capslock insert | The remaining named keys. |
numpad0-numpad9 | The keypad digits. numpad_add, numpad_subtract, numpad_multiply, numpad_divide, numpad_decimal and numpad_separator cover the rest of it. |
` - = [ ] \ ; ' , . / | Punctuation keys, written as the character itself. |
"[KeyA]" "[Digit0]" "[Slash]" | A scan code in square brackets binds the physical key, so the shortcut survives a change of keyboard layout. |
Overriding and removing defaults
| Syntax | What it does |
|---|---|
Rules are evaluated bottom to top | The first rule matching both the key and the when clause is the one that runs. |
Your file is appended below the defaults | Which is why a rule you write beats the built-in rule for the same key without your touching the default. |
{ "key": "tab", "command": "-jumpToNextSnippetPlaceholder" } | A minus in front of the command removes that default rule rather than adding one. |
{ "key": "tab", "command": "" } | An empty command disables every binding for that key. |
Two rules, same key, different when | How to keep a default and add your own: narrow yours with a when clause so the two never both match. |
A binding that silently does nothing | Nearly always a when clause that is false where you are pressing it, or a command ID that does not exist. |
when clause contexts
| Syntax | What it does |
|---|---|
editorTextFocus | The text in an editor has focus — the cursor is blinking. |
editorFocus | An editor has focus, either its text or one of its widgets. |
editorHasSelection | Text is selected. |
editorHasMultipleSelections | More than one region is selected, which is to say multiple cursors. |
!editorReadonly | The editor is not read-only. This one is almost always written negated. |
editorLangId == 'python' | Bind a key for one language only. |
resourceExtname == '.md' | Bind by file extension. resourceFilename, resourceDirname and resourceScheme match the other parts of the URI. |
isInDiffEditor | The active editor is a diff. |
terminalFocus | The integrated terminal has focus. |
inputFocus and listFocus | A text input has focus, or a list such as the Explorer does. |
suggestWidgetVisible / findWidgetVisible | The suggestion popup or the find box is open — this is how Enter and Escape mean different things in different places. |
inDebugMode | A debug session is running. |
isMac / isWindows / isLinux / isWeb | Platform tests, for a keybindings file you sync across machines. |
! && || | Not, and, or. |
== != =~ | Equality, inequality, and a regular-expression match. |
in / not in | Look one context key's value up inside another context key's value. |
Command IDs worth binding
| Syntax | What it does |
|---|---|
workbench.action.showCommands | The Command Palette. |
workbench.action.quickOpen | Quick Open, by file name. |
editor.action.addSelectionToNextFindMatch | Add a cursor at the next occurrence — the command behind Ctrl+D. |
editor.action.selectHighlights | Select every occurrence at once. |
editor.action.insertCursorAbove / insertCursorBelow | Add a cursor on the line above or below. |
editor.action.insertCursorAtEndOfEachLineSelected | One cursor at the end of every selected line. |
editor.action.moveLinesUpAction / moveLinesDownAction | Move the current line. |
editor.action.copyLinesUpAction / copyLinesDownAction | Duplicate it. |
editor.action.deleteLines | Delete the whole line. |
editor.action.commentLine / editor.action.blockComment | Toggle a line comment or a block comment. |
editor.action.formatDocument / editor.action.formatSelection | Format the file, or only what is selected. |
editor.action.quickFix | Open the Quick Fix menu for the problem under the cursor. |
editor.action.rename | Rename a symbol everywhere it is used. |
editor.action.revealDefinition / editor.action.goToReferences | Go to the definition; list every reference. |
editor.action.smartSelect.expand / smartSelect.shrink | Grow and shrink the selection by syntax node. |
workbench.action.gotoSymbol / workbench.action.showAllSymbols | Symbols in this file; symbols anywhere in the workspace. |
workbench.action.terminal.toggleTerminal / terminal.new | Show or hide the integrated terminal, or open another one. |
workbench.action.toggleSidebarVisibility / workbench.action.togglePanel | The two panes people toggle most. |
workbench.action.findInFiles / workbench.action.replaceInFiles | Search and replace across the workspace. |
workbench.action.tasks.runTask | Run a task — worth binding with an args object that names the task you run every day. |
Worth knowing
- Never type a command ID from memory. Open Default Keyboard Shortcuts (JSON) beside your own file, find the rule you want to change, and copy its command and when values across — a wrong identifier does not raise an error anywhere, it simply produces a key that does nothing, which is the hardest kind of mistake to spot.
- Rules are evaluated from bottom to top and your file is appended below the defaults, so the last matching rule wins. That single fact is the whole override mechanism: you never edit a default rule, you add one that is found first. It is also why two of your own rules for the same key means the lower one is the one that runs.
- When a combination does nothing at all, find out whether the key ever reached the editor before you rewrite the rule. Developer: Toggle Keyboard Shortcuts Troubleshooting logs each dispatched shortcut to the Output panel, which separates a when clause that is false from a keypress the window manager, the browser or the OS took first.
Try a snippet instead of reading about it
Reference is faster when you can run the thing. Paste a snippet into AltF Code, the free in-browser editor — real syntax highlighting for HTML, CSS, JavaScript, Python, SQL, JSON and more, with HTML, CSS and JavaScript running live in the preview. No install and no sign-up.
Open the editorVS Code Keybindings — common questions
- How do I change a keyboard shortcut in VS Code?
- Press Ctrl+K Ctrl+S (Cmd+K Cmd+S on a Mac) to open the Keyboard Shortcuts editor, find the command and rebind it there. For anything conditional, use the Open Keyboard Shortcuts (JSON) command instead and add a rule with key, command and when fields — your rules sit below the defaults, so they take precedence automatically.
- Where is the VS Code keybindings.json file?
- It sits beside settings.json in your User folder: %APPDATA%\Code\User\keybindings.json on Windows, ~/Library/Application Support/Code/User/keybindings.json on macOS and ~/.config/Code/User/keybindings.json on Linux. VS Code only creates it once you save a custom binding, so opening it through the Command Palette is more reliable than looking for the file.
- How do I remove a default keyboard shortcut?
- Add a rule whose command is the default command with a minus in front of it, as in { "key": "tab", "command": "-jumpToNextSnippetPlaceholder" }. That removes the default rather than adding a binding. To disable every command bound to a key at once, give that key an empty command string instead.
- What is a when clause?
- A boolean expression that decides where a binding is live, so the same key can do different things in the editor, the terminal and the file list. It is written over context keys such as editorTextFocus, terminalFocus, editorLangId and inDebugMode, combined with !, && and ||, and compared with ==, != or the regular-expression operator =~.