Visual Studio Code keybindings – Running two or more commands with one shortcut

Update: released for vscode v1.77, more at run multiple commands like a macro.

You are able to do this:

{
  "command": "runCommands",
  "key": "alt+r", // whatever keybinding
  "args": {
    "commands": [
      // commands to run in sequence
      "workbench.action.files.save",
      "workbench.action.terminal.focus"
    ]
  }
}

The command runCommands is built-in, so no extension is necessary for your use case. But see the link above, some use cases might require a macro extension.


Previous answer:

You would need a macro extension to run multiple commands from one keybinding.

I now use multi-command and there are other macro extensions now.

You can use this keybinding (in your keybindings.json) with the multi-command extension – no need for anything in settings.json:

{
  "key": "oem_8", // or whatever keybinding you wish
  "command": "extension.multiCommand.execute",
  "args": {
    "sequence": [
      "workbench.action.files.save",
      "workbench.action.terminal.focus"
    ]
  },
  "when": "editorTextFocus" // if you want this, you probably do
}

If you have more complicated macros you can still build them in your settings.json if you wish.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)