Skip to main content

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

SyntaxWhat it does
Ctrl+K Ctrl+S / Cmd+K Cmd+SOpen the Keyboard Shortcuts editor — the searchable table of every binding, default and custom.
Preferences: Open Keyboard ShortcutsThe 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.openGlobalKeybindingsThe command ID behind the Keyboard Shortcuts editor.
workbench.action.openGlobalKeybindingsFileThe command ID behind Open Keyboard Shortcuts (JSON).
workbench.action.openDefaultKeybindingsFileThe command ID behind the read-only defaults.
%APPDATA%\Code\User\keybindings.jsonWhere the file lives on Windows, beside settings.json in the same User folder.
~/Library/Application Support/Code/User/keybindings.jsonThe same folder on macOS.
~/.config/Code/User/keybindings.jsonAnd on Linux. VS Code only writes the file once you save a binding of your own.
Developer: Toggle Keyboard Shortcuts TroubleshootingLog every dispatched shortcut to the Output panel, so you can see what the editor actually received.

The shape of a rule

SyntaxWhat it does
[ { ... }, { ... } ]The whole file is one JSON array of rules. A trailing comma is the usual reason a file stops applying.
// a commentComments 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

SyntaxWhat 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-9Letter and digit keys.
f1-f19The function keys.
left up right down pageup pagedown end homeNavigation keys.
tab enter escape space backspace deleteEditing keys.
pausebreak capslock insertThe remaining named keys.
numpad0-numpad9The 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

SyntaxWhat it does
Rules are evaluated bottom to topThe first rule matching both the key and the when clause is the one that runs.
Your file is appended below the defaultsWhich 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 whenHow 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 nothingNearly always a when clause that is false where you are pressing it, or a command ID that does not exist.

when clause contexts

SyntaxWhat it does
editorTextFocusThe text in an editor has focus — the cursor is blinking.
editorFocusAn editor has focus, either its text or one of its widgets.
editorHasSelectionText is selected.
editorHasMultipleSelectionsMore than one region is selected, which is to say multiple cursors.
!editorReadonlyThe 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.
isInDiffEditorThe active editor is a diff.
terminalFocusThe integrated terminal has focus.
inputFocus and listFocusA text input has focus, or a list such as the Explorer does.
suggestWidgetVisible / findWidgetVisibleThe suggestion popup or the find box is open — this is how Enter and Escape mean different things in different places.
inDebugModeA debug session is running.
isMac / isWindows / isLinux / isWebPlatform tests, for a keybindings file you sync across machines.
! && ||Not, and, or.
== != =~Equality, inequality, and a regular-expression match.
in / not inLook one context key's value up inside another context key's value.

Command IDs worth binding

SyntaxWhat it does
workbench.action.showCommandsThe Command Palette.
workbench.action.quickOpenQuick Open, by file name.
editor.action.addSelectionToNextFindMatchAdd a cursor at the next occurrence — the command behind Ctrl+D.
editor.action.selectHighlightsSelect every occurrence at once.
editor.action.insertCursorAbove / insertCursorBelowAdd a cursor on the line above or below.
editor.action.insertCursorAtEndOfEachLineSelectedOne cursor at the end of every selected line.
editor.action.moveLinesUpAction / moveLinesDownActionMove the current line.
editor.action.copyLinesUpAction / copyLinesDownActionDuplicate it.
editor.action.deleteLinesDelete the whole line.
editor.action.commentLine / editor.action.blockCommentToggle a line comment or a block comment.
editor.action.formatDocument / editor.action.formatSelectionFormat the file, or only what is selected.
editor.action.quickFixOpen the Quick Fix menu for the problem under the cursor.
editor.action.renameRename a symbol everywhere it is used.
editor.action.revealDefinition / editor.action.goToReferencesGo to the definition; list every reference.
editor.action.smartSelect.expand / smartSelect.shrinkGrow and shrink the selection by syntax node.
workbench.action.gotoSymbol / workbench.action.showAllSymbolsSymbols in this file; symbols anywhere in the workspace.
workbench.action.terminal.toggleTerminal / terminal.newShow or hide the integrated terminal, or open another one.
workbench.action.toggleSidebarVisibility / workbench.action.togglePanelThe two panes people toggle most.
workbench.action.findInFiles / workbench.action.replaceInFilesSearch and replace across the workspace.
workbench.action.tasks.runTaskRun 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 editor

VS 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 =~.