35

Is it possible to have multiple actions assigned to one keyboard shortcut in visual studio code?

For example: Move cursor up x 3 set to "ctrl + w"

Thanks in advance.

M. Robertson
  • 409
  • 4
  • 5
  • See https://stackoverflow.com/questions/75808371/how-can-i-run-multiple-commands-with-a-single-vs-code-keybinding-without-an-exte/75808372#75808372 - you typically do not need an extension to run multiple commands with one shortcut as of vscode v1.77. – Mark Apr 10 '23 at 01:01

2 Answers2

22

It's possible with extensions like Commands [Note: Created by the post's author]

settings.json

"commands.commands": {
    "down3": {
        "sequence": [
            "cursorDown",
            "cursorDown",
            "cursorDown",
        ],
    },
},

keybindings.json

{
    "key": "ctrl+w",
    "command": "down3",
},

Or with just keybindings.json

{
    "key": "ctrl+w",
    "command": "commands.run",
    "args": [
        "cursorDown",
        "cursorDown",
        "cursorDown"
    ]
},

Feature request to support Macro like keybindings #871.


Although, for this particular example it's better to use the built-in command (to avoid any jumpiness):

{
    "key": "ctrl+w",
    "command": "cursorMove",
    "args": {
        "to": "down",
        "by": "line",
        "value": 3
    }
}

https://code.visualstudio.com/api/references/commands

Baum mit Augen
  • 49,044
  • 25
  • 144
  • 182
Alex
  • 59,571
  • 22
  • 137
  • 126
1

I use the macros extension:

in settings.json:

"macros": {
    "showGit": ["workbench.view.scm", "git-graph.view"]
}

then in keybindings.json:

{
    "key": "ctrl+shift+g",
    "command": "showGit"
}
wjandrea
  • 28,235
  • 9
  • 60
  • 81
Nitsan Baleli
  • 5,393
  • 3
  • 30
  • 52