5. Keyboard Shortcuts Customization

While VS Code comes with highly intuitive default shortcuts, every developer has unique muscle memory. If you are migrating from Sublime Text, IntelliJ, or Vim, or simply want to assign dedicated keys to your favorite extensions, you can fully customize VS Code's **Keyboard Shortcuts**.

The Shortcuts UI Dashboard

VS Code provides an interactive, searchable visual dashboard to manage shortcuts:

  • Open the keyboard shortcuts UI using: Ctrl + K then Ctrl + S (or Cmd + K then Cmd + S on macOS).
  • Type any action description (e.g., "Format Document") or key combo (e.g., `ctrl+shift`) to inspect current mappings.
  • Double-click any entry, press your desired key combination, and press Enter to assign it!

Detecting & Resolving Conflicts

What happens if you assign a key combination that is already used by another action? VS Code warns you of conflicts directly inside the prompt dialog. To inspect conflicting mappings:

  • Inside the Keyboard Shortcuts search bar, prefix your search with double quotes to find a specific key assignment—e.g. searching for "ctrl+d" finds all actions bound to that exact hotkey, letting you remove or edit secondary bindings.

Advanced: Editing `keybindings.json` Direct

For advanced developers who want to declare complex actions, customize "when" clauses, or share bindings across machines, editing the **`keybindings.json`** file directly is the best option.

To open it: click the open-file icon in the top right corner of the Keyboard Shortcuts dashboard (resembling a page with an arrow). Here is an example structure of `keybindings.json`:

[
    // 1. Rebind 'Format Document' to Ctrl+F
    {
        "key": "ctrl+f",
        "command": "editor.action.formatDocument",
        "when": "editorHasDocumentFormattingProvider && editorTextFocus && !editorReadonly"
    },
    
    // 2. Disable default 'Find' command
    {
        "key": "ctrl+f",
        "command": "-actions.find"
    },
    
    // 3. Multi-command custom workflow: Open terminal and run build
    {
        "key": "ctrl+alt+b",
        "command": "workbench.action.terminal.sendSequence",
        "args": { "text": "npm run build\n" }
    }
]

Understanding "When" Clauses

The when property is incredibly powerful. It allows a keybinding to execute different actions depending on the active context! For example:

  • editorTextFocus: The key only triggers when the text editor is active.
  • terminalFocus: Triggers when your cursor is inside the terminal panel.
  • sidebarVisible: Triggers only if the sidebar is expanded.
Pro Tip: Don't want to reconfigure keys manually? VS Code provides **Keymap Extensions** in the marketplace! You can install the Sublime, Atom, Eclipse, or IntelliJ Keymap packages, and VS Code will adapt its shortcuts to match your previous editor's layouts instantly!