问题
I have an existing shortcut which maximize the terminal window,
{
"key": "ctrl+`",
"command": "workbench.action.toggleMaximizedPanel"
}
I would like to add an additional command to the shortcut to shift the focus to the terminal window when it is maximized and back to editor window when it is minimized. is this possible in vscode?
回答1:
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.
来源:https://stackoverflow.com/questions/55160717/shortcut-with-multiple-command-in-vscode