6

How can I add multiple keyboard shortcuts to a single command in VS Code?

As an example (from the comments), ctrl + 0 & ctrl + 1 should both do the same command/action. So completely separate shortcuts doing the same command.

4
  • Are you thinking like ctrl+k, ctrl+c to comment a block (as in multiple keys in series to do a thing), or are you thinking ctrl+0 and ctrl+1 should do the same thing?
    – zedfoxus
    Commented Jun 6, 2020 at 18:05
  • That would be a macro Commented Jun 6, 2020 at 18:11
  • @zedfoxus ctrl + 0 & ctrl + 1 should do the same action/command. Commented Jun 6, 2020 at 18:44
  • @CharlieFish does the answer below get you what you wanted?
    – zedfoxus
    Commented Jun 8, 2020 at 13:18

1 Answer 1

7

Let's say there are 2 bindings to close window like so:

enter image description here

Let's say we want to add one more keybinding like CMD+K, CMD+1. You could do that by right-clicking a command and choosing copy like so:

enter image description here

Then, click on an icon on the top right corner to open keyboard shortcuts JSON. The icon has an curved arrow on a page:

enter image description here

Your user-defined keybindings.JSON will show up. Type this in it:

// Place your key bindings in this file to override the defaults
[
    {
        "key": "cmd+k cmd+1",
        "command": "workbench.action.closeWindow"
    }
]

Save and close.

Now you will see 3 keybindings for the action like so:

enter image description here

Now, try your new keybinding.

1
  • 4
    The faster way is to right click the command and select "Add Keybinding..."
    – Jasperan
    Commented Dec 22, 2021 at 21:15

Not the answer you're looking for? Browse other questions tagged or ask your own question.