终端聚焦时切换侧边栏可见性

Toggle side bar visibility when terminal is focused

Ubuntu 20.04,gnome-terminal

我尝试让 CTRL+B 在终端聚焦时切换侧边栏可见性。这是我的配置尝试:

{
    "key": "ctrl+b",
    "command": "workbench.action.toggleSidebarVisibility",
    "when": "terminalFocus"
}

不幸的是,当我专注于终端输入时,按 CTRL+B 没有任何效果,也不会切换侧边栏。配置有什么问题?

发生的情况是您的键绑定被发送到 shell,而不是 Visual Studio 代码。您需要向 terminal.integrated.commandsToSkipShell 数组添加您希望 Visual Studio 代码在执行匹配的键绑定时处理的命令,并且您专注于集成终端。在这种情况下,切换侧边栏的命令:

    "terminal.integrated.commandsToSkipShell": [
        "workbench.action.toggleSidebarVisibility"
    ]

您不需要创建自定义键 binding/modify 已有的键就有新的 when 条件。

此设置的描述为:

A set of command IDs whose keybindings will not be sent to the shell but instead always be handled by VS Code. This allows keybindings that would normally be consumed by the shell to act instead the same as when the terminal is not focused, for example Ctrl+P to launch Quick Open