In vscode v1.77 is a new command runCommands
which allows you to run a sequence of commands much liek a traditional macro extension does. With the following keybindings you can do what you want with no macro extension:
{
"key": "ctrl+`", // use the same keybinding below
"command": "runCommands",
"args": {
"commands": [
"workbench.action.toggleMaximizedPanel",
"workbench.action.terminal.focus",
]
},
"when": "!terminalFocus"
},
{
"key": "ctrl+`", // same keybinding as above
"command": "runCommands",
"args": {
"commands": [
"workbench.action.toggleMaximizedPanel",
"workbench.action.focusActiveEditorGroup",
]
},
"when": "terminalFocus" // terminal will be focused when it is maximized
}
I note there is a new requirement that the Panel be center-aligned for this to work.
[Before vscode 1.77]
I think you will have to use a macro extension like multi-command to run multiple commands with one keybinding. Once you have installed multi-command, in your settings.json:
"multiCommand.commands": [
{
"command": "multiCommand.toggleTerminalAndFocusTerminal",
"sequence": [
"workbench.action.toggleMaximizedPanel",
"workbench.action.terminal.focus",
]
},
{
"command": "multiCommand.toggleTerminalAndFocusEditor",
"sequence": [
"workbench.action.toggleMaximizedPanel",
"workbench.action.focusActiveEditorGroup",
]
}
],
and then these keybindings:
{
"key": "ctrl+`",
"command": "extension.multiCommand.execute",
"args": { "command": "multiCommand.toggleTerminalAndFocusTerminal" },
"when": "!terminalFocus"
},
{
"key": "ctrl+`",
"command": "extension.multiCommand.execute",
"args": { "command": "multiCommand.toggleTerminalAndFocusEditor" },
"when": "terminalFocus"
},
So the same keybinding, Ctrl-backTick will trigger one of the two commands depending on whether the terminal has focus - note the "when": "!terminalFocus"
meaning when the terminal does not have focus.