在 vscode v1.77 中是一个新命令runCommands
它允许您运行一系列命令,就像传统的宏扩展一样。使用以下键绑定,您可以在没有宏扩展的情况下执行您想要的操作:
{
"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
}
我注意到有一个新的要求,即面板必须居中对齐才能发挥作用。
[vscode 1.77 之前]
我认为你必须使用像这样的宏扩展多命令使用一个键绑定运行多个命令。安装多命令后,在 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",
]
}
],
然后是这些键绑定:
{
"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.