我正在尝试找出是否有一种方法可以设置一个快捷键来快速切换内置终端中打开的终端窗口,而不必每次都要点击下拉选择器。有人知道在创建个人键绑定时使用的命令或者我可以在哪里看到VSC的所有可能命令列表吗?提前感谢您!
我正在尝试找出是否有一种方法可以设置一个快捷键来快速切换内置终端中打开的终端窗口,而不必每次都要点击下拉选择器。有人知道在创建个人键绑定时使用的命令或者我可以在哪里看到VSC的所有可能命令列表吗?提前感谢您!
如果您想要一些比使用任意键绑定更具流畅感的东西,您可以让 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"
}
根据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"}
这是我在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)
根据Haini的回答,将以下代码添加到您的keybindings.json
文件中:
{
"key": "shift+up",
"command": "workbench.action.terminal.focusPrevious",
"when": "terminalFocus"
},
{
"key": "shift+down",
"command": "workbench.action.terminal.focusNext",
"when": "terminalFocus"
}
来源:https://code.visualstudio.com/docs/editor/integrated-terminal使用“focus next ⇧⌘]”和“focus previous ⇧⌘[”在终端组之间导航。
要在终端之间切换,您可以使用以下命令
在 Mac 上
此命令将在终端组之间切换。要查找所有命令:
command + shift + p(在 Mac 上)
打开键盘快捷方式
目前编辑器和终端已经可以切换标签页了,只需尝试使用ctrl + page up或ctrl + page down。
{
"key": "ctrl+`",
"command": "easyMotion.quickMove",
"args": {
"inputType": "TerminalTabs",
"repeatCountFormat": "Number",
"matchFuzziness": "2"
},
"when": "terminalFocus"
}
]
workspace
而不是workbench
,所以正确的值应该是:workbench.action.openPreviousRecentlyUsedEditorInGroup
。 - Ofir