Search code examples
visual-studio-codecommandkey-bindings

How to bind one key to multiple commands in VSCode


I'm trying to make the key Ctrl+UpArrow execute both commands cursorUp and scrollLineUp.

I was hoping that this would work, but it doesn't:

{
  "key": "ctrl+up",
   "command": ["cursorUp", "scrollLineUp"], // This doesn't work
   "when": "editorTextFocus"
}

How do I do that in VSCode?


Solution

  • This is currently not possible, but the corresponding feature request is tracked here. However you should take a look to the macros extension. It enables you to chain different commands to a single custom command. This custom command then can be bound to a hotkey. In your case you could add this to your settings.json:

    "macros": {
        "myCustomCommand": [
            "cursorUp",
            "scrollLineUp"
        ]
    }
    

    And then add your custom hotkey to the keybindings.json:

    {
      "key": "ctrl+up",
      "command": "macros.myCustomCommand"
    }