在 VSCode 中使用多个命令的快捷方式 [英] Shortcut with multiple command in VSCode

查看:25
本文介绍了在 VSCode 中使用多个命令的快捷方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可以最大化终端窗口的现有快捷方式,

I have an existing shortcut which maximize the terminal window,

{
        "key": "ctrl+`",
        "command": "workbench.action.toggleMaximizedPanel"
}

我想在快捷方式中添加一个附加命令,以便在最大化时将焦点转移到终端窗口,并在最小化时将焦点移回编辑器窗口.这在 vscode 中可行吗?

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?

推荐答案

我认为你将不得不使用像 multi-command 使用一个键绑定运行多个命令.安装多命令后,在 settings.json 中:

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",
      ]
    }
],

然后是这些键绑定:

{
  "key": "ctrl+`",
  "command": "extension.multiCommand.execute",
  "args": { "command": "multiCommand.toggleTerminalAndFocusTerminal" },
  "when": "!terminalFocus"
},

{
  "key": "ctrl+`",
  "command": "extension.multiCommand.execute",
  "args": { "command": "multiCommand.toggleTerminalAndFocusEditor" },
  "when": "terminalFocus"
},

所以同样的按键绑定,Ctrl-backTick 将根据终端是否有焦点触发两个命令之一——注意"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.

这篇关于在 VSCode 中使用多个命令的快捷方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆