Multiple actions on one keyboard shortcut in vscode [duplicate]
Asked Answered
F

2

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.

Flews answered 3/5, 2016 at 16:12 Comment(1)
See #75808871 - you typically do not need an extension to run multiple commands with one shortcut as of vscode v1.77.Aldas
M
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

Materially answered 13/5, 2017 at 6:58 Comment(0)
L
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"
}
Launch answered 15/12, 2020 at 13:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.