How to Change Keyboard Shortcuts and Edit keybindings.json in VS Code

Customize any VS Code keyboard shortcut using the Keyboard Shortcuts editor or by editing keybindings.json directly. Add, change, and remove shortcuts safely.

5 min read

VS Code keyboard shortcuts can be changed in the visual Keyboard Shortcuts editor or in your user keybindings.json file. Use the visual editor for ordinary changes; edit JSON when you need a precise command ID, chord, or conditional rule.

Open the Keyboard Shortcuts editor

Press Ctrl+K Ctrl+S on Windows and Linux, or Cmd+K Cmd+S on macOS.

This is a chord: press Ctrl+K, then press Ctrl+S. On macOS, press Cmd+K, then Cmd+S.

The editor lists every command in VS Code. Each row shows the command name, its current keyboard shortcut, its source (built-in, user, or extension), and an optional when clause that controls when it is active.

Change a shortcut

Find the command

Type part of the command name in the search bar. For example, type "delete line" to find the Delete Line command.

Edit the keybinding

Click the pencil icon on the left of the row, or double-click the row. A dialog appears.

Press your new keys

Press the key combination you want to assign. The dialog shows the keys you pressed. Press Enter to save.

The new shortcut takes effect immediately. Run the command with the new keys to confirm it works. If the editor shows a conflict, right-click the entry and select Show Same Keybindings before deciding which rule to change.

Remove a shortcut

Right-click a user-defined entry in the Keyboard Shortcuts editor and select Remove Keybinding. For an overridden default, use Reset Keybinding to remove the user override and reveal the default again. Test the keys afterward to confirm the expected command runs.

Edit keybindings.json directly

For more advanced changes, open the JSON file. Click the Open Keyboard Shortcuts (JSON) button in the top-right of the Keyboard Shortcuts editor (the icon with curly braces and an arrow).

Your user keybindings.json file opens as a JSON array. Copy its current contents before making several manual changes so you can restore your previous rules. A complete one-rule file looks like this:

jsonjson
[
  {
    "key": "ctrl+shift+r",
    "command": "editor.action.rename",
    "when": "editorTextFocus && !editorReadonly"
  }
]
  • key: The key combination. Modifiers are Ctrl, Shift, Alt, and Cmd (macOS).
  • command: The VS Code command ID to run.
  • when: Optional. A condition that controls when the shortcut is active.

Find a command ID

To find the ID for any command, open the Keyboard Shortcuts editor and right-click a command. Select Copy Command ID. The ID is a string like editor.action.formatDocument.

You can also run Developer: Toggle Keyboard Shortcuts Troubleshooting. Press the shortcut and inspect the Keyboard Shortcuts log in the Output panel to see which key event and command VS Code resolved. Run the command again when finished to stop the diagnostic logging.

Create a chord shortcut

A chord is two separate key presses. Write it with a space between the two combinations:

jsonjson
[
  {
    "key": "ctrl+k ctrl+f",
    "command": "editor.action.formatSelection",
    "when": "editorHasSelection && editorTextFocus"
  }
]

Press Ctrl+K, release, then press Ctrl+F. Both presses together trigger the command.

Add a when clause

A when clause limits when a shortcut works. Common contexts:

ContextMeaning
editorTextFocusFocus is in a text editor
editorHasSelectionText is selected
editorLangId == pythonFile is Python
inDebugModeA debug session is active
terminalFocusFocus is in the terminal

For example, a shortcut that only works in JavaScript files:

jsonjson
[
  {
    "key": "ctrl+shift+d",
    "command": "editor.action.copyLinesDownAction",
    "when": "editorTextFocus && editorLangId == javascript"
  }
]

Save the file, focus a JavaScript editor, and press the shortcut. A copy appearing directly below the current line confirms the rule and its condition matched. In a different language, the shortcut should not trigger this rule.

Install a Keymap extension

If you are switching from another editor, install a Keymap extension to get its shortcuts without remapping everything manually.

Open File > Preferences > Migrate Keyboard Shortcuts from... and choose a keymap from the Marketplace results. A keymap is an extension that can replace many shortcuts at once, so verify its publisher and review its listing before installation. If the resulting bindings are confusing, disable the keymap extension and your previous user rules remain available.

What to try if a shortcut does not work

Start with reversible checks. Save keybindings.json and fix any red syntax diagnostics. Then open the Keyboard Shortcuts editor, locate the command, and use Show Same Keybindings to inspect conflicts.

If the shortcut is valid but still does not fire, another rule or the operating system may be consuming the key press. Use the troubleshooting command described above and inspect the log. On Linux, restart VS Code after changing the operating system keyboard layout because VS Code caches the layout at startup.

The official keyboard shortcuts documentation covers conflicts, command IDs, when clauses, removal rules, troubleshooting, and keymap migration.

Next steps

Now that you can customize shortcuts, learn how to change the editor font and enable ligatures for a more comfortable coding experience. To maintain different user-level shortcut sets, see how VS Code profiles work.

Rune AI

Rune AI

Key Insights

  • Open the Keyboard Shortcuts editor with Ctrl+K Ctrl+S (Cmd+K Cmd+S on macOS).
  • Use the pencil control to record a new key combination.
  • Keep keybindings.json as a valid top-level JSON array.
  • Use when clauses to limit shortcuts to a specific context.
  • Use Show Same Keybindings and keyboard shortcut troubleshooting to diagnose conflicts safely.
RunePowered by Rune AI

Frequently Asked Questions

How do I reset a keyboard shortcut to the default?

Open the Keyboard Shortcuts editor (Ctrl+K Ctrl+S), right-click the modified entry, and select Reset Keybinding. If you edited keybindings.json directly, delete only the user rule you added and save.

What is a chord in VS Code shortcuts?

A chord is two key combinations entered in sequence. For example, Ctrl+K followed by Ctrl+S opens the Keyboard Shortcuts editor. Chords are written with a space between the combinations.

Can I create a shortcut that only works in certain files?

Yes. Add a when clause to the keybinding. For example, "when": "editorLangId == typescript" limits the rule to TypeScript editors. Use the Keyboard Shortcuts editor to inspect existing when clauses and context keys.

Conclusion

You can customize any VS Code shortcut through the Keyboard Shortcuts editor or by editing keybindings.json. The visual editor is the easiest path. The JSON file gives you more control, including chords, command arguments, and conditional when clauses.