VS Code Key Binding可以在终端屏幕之间快速切换?

时间:2017-05-19 08:31:09

标签: visual-studio-code

我正在试图弄清楚是否有办法设置一个键绑定,以便在我在内置终端中打开的终端窗口之间快速切换,而不是每次都必须单击下拉选择器。在制作个人密钥绑定时,有没有人知道这个命令,或者我可以看到VSC所有可能命令的列表?提前谢谢!

5 个答案:

答案 0 :(得分:16)

如果你想要一些比使用任意键绑定更流畅的东西,你可以使用Ctrl + Tab和Ctrl + Shift + Tab来进行编辑器切换和终端切换。

使用ctrl+shift+p搜索keyboard file打开您的密钥绑定文件。然后添加..

{ 
  "key": "ctrl+tab",            
  "command": "workbench.action.openNextRecentlyUsedEditorInGroup",
  "when": "editorFocus" 
},
{ "key": "shift+ctrl+tab",      
  "command": "workspace.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"
}

答案 1 :(得分:12)

Microsofts Documentation开始提示:

  

提示:如果您广泛使用多个终端,则可以添加密钥   概述了focusNext,focusPrevious和kill命令的绑定   在Key Bindings部分中,允许使用它们之间的导航   只有键盘。

来自here

  

其他终端命令可用,可以绑定到您的终端   首选键盘快捷键。他们是:   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.

只需将这些快捷方式分配给您首选的键绑定,就可以了。

这可能不是直接跳转到终端的解决方案(例如像vims 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

e.g。 { "key": "yourkeybinding", "command": "workbench.action.terminal.focusAtIndex1"}

答案 2 :(得分:4)

这是我构建的解决方案,适用于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)

也是如此

答案 3 :(得分:3)

根据Haini回答,将以下代码添加到keybindings.json

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

现在,您可以使用 shift + down shift + up

在终端之间切换

答案 4 :(得分:0)

至于现在它已经在编辑器和终端上切换标签,只需尝试 ctrl + page up 或 ctrl + page down。