快速在终端屏幕之间切换的 VS Code 键绑定?

48

我正在尝试找出是否有一种方法可以设置一个快捷键来快速切换内置终端中打开的终端窗口,而不必每次都要点击下拉选择器。有人知道在创建个人键绑定时使用的命令或者我可以在哪里看到VSC的所有可能命令列表吗?提前感谢您!

8个回答

67

如果您想要一些比使用任意键绑定更具流畅感的东西,您可以让 Ctrl+Tab 和 Ctrl+Shift+Tab 同时用于编辑器切换和终端切换。

使用 Ctrl+Shift+P 打开您的键绑定文件,搜索 打开键盘快捷方式 (JSON)。然后添加...

{ 
  "key": "ctrl+tab",            
  "command": "workbench.action.openNextRecentlyUsedEditorInGroup",
  "when": "editorFocus" 
},
{ "key": "shift+ctrl+tab",      
  "command": "workbench.action.openPreviousRecentlyUsedEditorInGroup",
  "when": "editorFocus" 
},
{
  "key": "ctrl+tab",
  "command": "workbench.action.terminal.focusNext",
  "when": "terminalFocus"
},
{
  "key": "ctrl+shift+tab",
  "command": "workbench.action.terminal.focusPrevious",
  "when": "terminalFocus"
}

2
谢谢!但是你有一个拼写错误——你写成了workspace而不是workbench,所以正确的值应该是:workbench.action.openPreviousRecentlyUsedEditorInGroup - Ofir
这似乎在当前的VSCode版本中有所不同: 在菜单栏中,转到“代码”->“首选项”->“键盘快捷方式”。搜索“焦点终端”。双击“终端:聚焦下一个终端”或“终端:聚焦上一个终端”,输入您的快捷键,按Enter。然后右键单击该行,单击“更改表达式”并输入“terminalFocus”。在我的当前VSCode版本中,找不到“键盘文件”。 - sschmidTU
2
此答案的更新:搜索“Open Keyboard Shortcuts(JSON)”,并仅使用两个terminalFocus条目。对于editorFocus,您可能希望保留默认设置。 - Travis Reeder
它对我不起作用,有什么建议吗? - Hazem Alabiad

26

根据Microsoft文档中的提示:

提示:如果您经常使用多个终端,可以添加键绑定来聚焦到下一个、上一个或关闭终端。在“键绑定”一节中有详细介绍。

另外,在这里可以找到其他终端命令,您可以将它们绑定到自己喜欢的键盘快捷键上。其中包括:workbench.action.terminal.focus:聚焦到终端。这类似于切换,但如果可见,将聚焦到终端而不是隐藏它。

workbench.action.terminal.focusNext: Focuses the next terminal instance. 
workbench.action.terminal.focusPrevious: Focuses the previous terminal instance. 
workbench.action.terminal.kill: Remove the current terminal instance.
workbench.action.terminal.runSelectedText: Run the selected text in the terminal instance.

只需将这些快捷方式分配给您喜欢的键绑定,您就可以开始使用了。

这可能不是直接跳转到终端的解决方案(例如像vim的gt2那样),但它肯定是一个好的开始。


编辑:刚才尝试了一下,发现您也可以聚焦于特定终端。只需将任何这些命令添加到您的keybindings.json中,您就可以开始使用了!

// - workbench.action.terminal.focusAtIndex1
// - workbench.action.terminal.focusAtIndex2
// - workbench.action.terminal.focusAtIndex3
// - workbench.action.terminal.focusAtIndex4
// - workbench.action.terminal.focusAtIndex5
// - workbench.action.terminal.focusAtIndex6
// - workbench.action.terminal.focusAtIndex7
// - workbench.action.terminal.focusAtIndex8
// - workbench.action.terminal.focusAtIndex9

例如:{ "key": "你的按键绑定", "command": "workbench.action.terminal.focusAtIndex1"}


1
这对我帮助很大!!谢谢 - Lucas Vinicius

13

这是我在OSX上为自己设计的一种解决方案,运行良好。

它模拟编辑器中用于打开新文件(cmd+n)和在选项卡之间切换(cmd+left|right)的相同快捷键,并且在终端视图获得焦点时,相同的快捷键也适用于终端。

按下 cmd+shift+p 并输入 keyboard 来查找 Preferences: Open Keyboard Shortcuts File

将以下内容添加到 keybindings.json 文件并保存。

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

它也同样适用于关闭终端(cmd+w)


5

根据Haini的回答,将以下代码添加到您的keybindings.json文件中:

{
  "key": "shift+up",
  "command": "workbench.action.terminal.focusPrevious",
  "when": "terminalFocus"
},
{
  "key": "shift+down",
  "command": "workbench.action.terminal.focusNext",
  "when": "terminalFocus"
}

现在,您可以使用Shift + DownShift + Up在终端之间切换。

1
在Mac上,对我来说 [] 可以让我在终端有焦点时切换不同的终端实例。我使用 j 在终端和编辑器之间切换焦点。
引用源码:

使用“focus next ⇧⌘]”和“focus previous ⇧⌘[”在终端组之间导航。

来源:https://code.visualstudio.com/docs/editor/integrated-terminal

1

要在终端之间切换,您可以使用以下命令

在 Mac 上

  1. cmd + shift + [
  2. cmd + shift + ]

此命令将在终端组之间切换。要查找所有命令:

command + shift + p(在 Mac 上)

打开键盘快捷方式


0

目前编辑器和终端已经可以切换标签页了,只需尝试使用ctrl + page up或ctrl + page down。


0
将以下代码添加到您的keybindings.json文件中。此代码设置了使用“EasyMotion”在终端选项卡之间切换的键绑定:还要从vs安装Easy motion。
 {
    "key": "ctrl+`",
    "command": "easyMotion.quickMove",
    "args": {
        "inputType": "TerminalTabs",
        "repeatCountFormat": "Number",
        "matchFuzziness": "2"
    },
    "when": "terminalFocus"
}

]


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接