Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 983
Ameen Avatar asked Mar 08 '18 15:03

Ameen


1 Answers

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"
}
like image 171
HaaLeo Avatar answered Sep 22 '22 13:09

HaaLeo