有人知道在Visual Studio Code中切换编辑器和集成终端的快捷键(Mac和Linux)吗?
当前回答
虽然VS Code有很多模式切换和导航快捷方式,但没有一个专门用于“从编辑器移动到终端,然后再返回”。但是,您可以通过重载键和使用when子句来组合这两个步骤。
解决方案
您可以通过向键绑定添加适当的设置来实现所需的效果。json文件。以下是必需的步骤:
打开命令面板(Ctrl+Shift+P Windows/Linux或⇧⌘P Mac)。 输入“首选项:打开键盘快捷键(JSON)”并按Enter。 将以下条目添加到键绑定中。json文件:
// Toggle between terminal and editor focus
{
"key": "ctrl+`",
"command": "workbench.action.terminal.focus"
},
{
"key": "ctrl+`",
"command": "workbench.action.focusActiveEditorGroup",
"when": "terminalFocus"
}
使用这些快捷键,您可以使用相同的击键在编辑器和集成终端之间集中注意力。
NOTE
这里建议的组合键现在作为默认值内置到VSCode中(从1.72.2开始,可能更早)。在尝试添加它之前,看看ctrl + '是否有效。
NOTE
在现代版本的VS Code(截至2022年)中,默认键盘快捷键(JSON)文件是只读的,所以这就是为什么对于自定义设置,你需要编辑一个单独的专用文件keybindings.json。
更多信息可以在Visual Studio官方文档页面上找到:
Visual Studio Code的键绑定:高级定制
其他回答
根据VS Code键盘快捷键文档页,切换集成终端的默认键绑定是“Ctrl+ '”。如果你不喜欢这个快捷方式,你可以在你的键绑定文件中添加类似的东西来改变它:
{ "key": "ctrl+l", "command": "workbench.action.terminal.toggleTerminal" }
似乎没有一个默认的键绑定来简单地聚焦底部面板。所以,如果你不想切换底部面板,你需要在你的keybindings文件中添加类似以下内容:
{ "key": "ctrl+t", "command": "workbench.action.focusPanel" }
使用keybindings.json中的键绑定:
CTRL+j和CTRL+k将焦点在编辑器组中的编辑器和终端中的终端窗口之间转移 CTRL+h和CTRL+l在包括终端在内的编辑器组之间转移焦点
(这些键绑定对vim用户来说应该特别自然。其他人可能希望把h/j/k/l换成左/下/上/右)
// In an editor group, ctrl+j and ctrl+k jump between editor windows
{ "key": "ctrl+j", "command": "workbench.action.nextEditorInGroup" },
{ "key": "ctrl+k", "command": "workbench.action.previousEditorInGroup" },
// In the terminal, ctrl+j and ctrl+k jump between terminal windows
{
"key": "ctrl+j",
"command": "workbench.action.terminal.focusNext",
"when": "terminalFocus && terminalHasBeenCreated && !terminalEditorFocus || terminalFocus && terminalProcessSupported && !terminalEditorFocus"
},
{
"key": "ctrl+k",
"command": "workbench.action.terminal.focusPrevious",
"when": "terminalFocus && terminalHasBeenCreated && !terminalEditorFocus || terminalFocus && terminalProcessSupported && !terminalEditorFocus"
},
// In the work area, ctrl+j and ctrl+k jump between editor groups
{ "key": "ctrl+h", "command": "workbench.action.focusPreviousGroup" },
{ "key": "ctrl+l", "command": "workbench.action.focusNextGroup" },
// in the first editor group terminal, jump "back" to the terminal (if there is a terminal open)
{
"key": "ctrl+h",
"when": " terminalHasBeenCreated && terminalIsOpen && activeEditorGroupIndex == 1",
"command": "workbench.action.terminal.focus"
},
// in the last editor group terminal, jump "forward" to the terminal (if there is a terminal open)
{
"key": "ctrl+l",
"when": "terminalHasBeenCreated && terminalIsOpen && activeEditorGroupLast",
"command": "workbench.action.terminal.focus"
},
// in the terminal, jump "back" to the last editor group
{
"key": "ctrl+h",
"command": "workbench.action.focusLastEditorGroup",
"when": "terminalFocus"
},
// in the terminal, jump "forward" to the last first group
{
"key": "ctrl+l",
"command": "workbench.action.focusFirstEditorGroup",
"when": "terminalFocus"
},
通常,VS Code使用ctrl+j打开终端,所以我创建了一个键绑定来切换与ctrl+k组合,如下在keybindings.json:
[
{
"key": "ctrl+k",
"command": "workbench.action.terminal.focus"
},
{
"key": "ctrl+k",
"command": "workbench.action.focusActiveEditorGroup",
"when": "terminalFocus"
}
]
虽然VS Code有很多模式切换和导航快捷方式,但没有一个专门用于“从编辑器移动到终端,然后再返回”。但是,您可以通过重载键和使用when子句来组合这两个步骤。
解决方案
您可以通过向键绑定添加适当的设置来实现所需的效果。json文件。以下是必需的步骤:
打开命令面板(Ctrl+Shift+P Windows/Linux或⇧⌘P Mac)。 输入“首选项:打开键盘快捷键(JSON)”并按Enter。 将以下条目添加到键绑定中。json文件:
// Toggle between terminal and editor focus
{
"key": "ctrl+`",
"command": "workbench.action.terminal.focus"
},
{
"key": "ctrl+`",
"command": "workbench.action.focusActiveEditorGroup",
"when": "terminalFocus"
}
使用这些快捷键,您可以使用相同的击键在编辑器和集成终端之间集中注意力。
NOTE
这里建议的组合键现在作为默认值内置到VSCode中(从1.72.2开始,可能更早)。在尝试添加它之前,看看ctrl + '是否有效。
NOTE
在现代版本的VS Code(截至2022年)中,默认键盘快捷键(JSON)文件是只读的,所以这就是为什么对于自定义设置,你需要编辑一个单独的专用文件keybindings.json。
更多信息可以在Visual Studio官方文档页面上找到:
Visual Studio Code的键绑定:高级定制
下面是一种添加自己的键绑定来切换焦点的方法。
打开VSCode 按Ctrl+Shift+P,搜索键盘快捷键并点击这个(首选项:打开键盘快捷键)。 在搜索面板中搜索“聚焦终端”并找到该选项(终端:聚焦终端视图)并单击加号图标。
输入你喜欢的没有使用的快捷方式,然后按Enter。 进入编辑器模式,尝试使用快捷方式。 现在按Alt+Shift+T进入终端。 想回去找编辑吗?只需按Ctrl+tab
在Windows 10机器上使用VSCode(1.52.1)进行测试
推荐文章
- 打开同一目录两次
- 如何从终端/命令行调用VS代码编辑器
- 如何在Visual Studio代码中重置设置?
- 如何将制表符转换为空格,反之亦然,在现有的文件
- 错误:'types'只能在.ts文件中使用- Visual Studio Code使用@ts-check
- Visual Studio Code: .git文件夹/文件隐藏
- Visual Studio Code:如何调试Python脚本的参数
- 如何在Visual Studio代码中触发参数提示?
- 在VS Code中禁用“Comments are not allowed In JSON”错误
- 使用正则表达式搜索和替换Visual Studio代码
- 如何缩进/格式选择的代码在Visual Studio代码?
- 如何禁用预览文件与点击在vs代码?
- Visual Studio代码更改文件资源管理器托盘的字体大小?
- 如何防止Visual Studio Code总是重新打开以前的文件或文件夹?
- VSCode单引号到双引号自动替换