visual studio code keybindings - Running two or more commands with one shortcut

12,320

Solution 1

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.

Solution 2

Another extension to run multiple commands: Commands

{
    "key": "oem_8",
    "command": "commands.run",
    "args": [
        "workbench.action.files.save",
        "workbench.action.terminal.focus"
    ],
    "when": "editorTextFocus"
}

I made this extension. It's great.

Share:
12,320
Nick
Author by

Nick

VBA, Javascript, SQL, C#, 🐍....etc

Updated on June 06, 2022

Comments

  • Nick
    Nick almost 2 years

    I have the following keybinding in VS code which toggles the position of the cursor between the active document and built-in terminal:

      // Toggle between terminal and editor focus
    {
        "key": "oem_8",
        "command": "workbench.action.terminal.focus"
    },
    {
        "key": "oem_8",
        "command": "workbench.action.focusActiveEditorGroup",
        "when": "terminalFocus"
    }
    

    Before i click the shortcut key to move the cursor to the terminal, i first have to save the active file.

    I would therefore like to run the file saving command, which after searching on google i believe is :workbench.action.files.save

    How would i do this please? i have tried adding the above code snippet at the end of the "command" line but it has not worked.

    cheers