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.

1

2 Answers 2

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

0
2

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"
}

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