有人知道在Visual Studio Code中切换编辑器和集成终端的快捷键(Mac和Linux)吗?


当前回答

下面是我的方法,它提供了在活动终端之间导航的一致方式,以及在终端和编辑器窗格之间跳转而无需关闭终端视图。您可以尝试将此添加到您的键绑定。我建议你使用键盘绑定UI (Mac上的cmd+K cmd+S),这样你就可以检查/管理冲突等。

这样,我可以使用ctrl+x <箭头方向>导航到任何可见的编辑器或终端。一旦光标在终端部分,您可以使用ctrl+x ctrl+up或ctrl+x ctrl+down在活动终端中循环。

cmd-J仍然用于隐藏/显示终端窗格。

    {
        "key": "ctrl+x right",
        "command": "workbench.action.terminal.focusNextPane",
        "when": "terminalFocus"
    },
    {
        "key": "ctrl+x left",
        "command": "workbench.action.terminal.focusPreviousPane",
        "when": "terminalFocus"
    },
    {
        "key": "ctrl+x ctrl+down",
        "command": "workbench.action.terminal.focusNext",
        "when": "terminalFocus"
    },
    {
        "key": "ctrl+x ctrl+up",
        "command": "workbench.action.terminal.focusPrevious",
        "when": "terminalFocus"
    },
    {
        "key": "ctrl+x up",
        "command": "workbench.action.navigateUp"
    },
    {
        "key": "ctrl+x down",
        "command": "workbench.action.navigateDown"
    },
    {
        "key": "ctrl+x left",
        "command": "workbench.action.navigateLeft",
        "when": "!terminalFocus"
    },
    {
        "key": "ctrl+x right",
        "command": "workbench.action.navigateRight",
        "when": "!terminalFocus"
    },

其他回答

为了在ctrl+ '组合之间进行切换,我尝试了所有列出的答案,但运气不好。对于那些像我一样有类似问题的人,尝试以下键绑定中的快捷方式。在VSCode 1.59+上测试

[
{
    "key": "ctrl+oem_8","command": "workbench.action.terminal.focus", "when": "!terminalFocus"
},
{
    "key": "ctrl+oem_8","command": "workbench.action.focusActiveEditorGroup", "when": "terminalFocus"
}
]

我把我的配置如下,因为我发现ctrl+ '有点难按。

{
  "key": "ctrl+k",
  "command": "workbench.action.focusActiveEditorGroup",
  "when": "terminalFocus"
},
{
  "key": "ctrl+j",
  "command": "workbench.action.terminal.focus",
  "when": "!terminalFocus"
}

我还配置了以下内容,以便在编辑器组之间移动。

{
  "key": "ctrl+h",
  "command": "workbench.action.focusPreviousGroup",
  "when": "!terminalFocus"
},
{
  "key": "ctrl+l",
  "command": "workbench.action.focusNextGroup",
  "when": "!terminalFocus"
}

顺便说一下,我在Mac上从系统首选项=>键盘=>修改器键配置了Caps Lock。

根据VS Code键盘快捷键文档页,切换集成终端的默认键绑定是“Ctrl+ '”。如果你不喜欢这个快捷方式,你可以在你的键绑定文件中添加类似的东西来改变它:

{ "key": "ctrl+l", "command": "workbench.action.terminal.toggleTerminal" }

似乎没有一个默认的键绑定来简单地聚焦底部面板。所以,如果你不想切换底部面板,你需要在你的keybindings文件中添加类似以下内容:

{ "key": "ctrl+t", "command": "workbench.action.focusPanel" }

ctrl+ ':专注于集成终端

ctrl+1:聚焦编辑器(如果Editor -2命令是ctrl+2)

更多信息:https://medium.com/p/21969576c09c

这不是确切的问题,但我发现它非常有用和相关。

如果有人想从一个终端切换到另一个终端,也可以在Visual Studio的集成终端面板中打开,您可以搜索:

终端:关注下一个终端

或者添加以下快捷键,用键盘组合更快。

  {
    "key": "alt+cmd+right",
    "command": "workbench.action.terminal.focusNext",
    "when": "terminalFocus"
  },
  {
    "key": "alt+cmd+left",
    "command": "workbench.action.terminal.focusPrevious",
    "when": "terminalFocus"
  },