有谁知道在 Visual Studio Code 中在编辑器和集成终端之间切换焦点的键盘快捷键(Mac 和 Linux)?
ctrl
+ ' ` ' 将是最好的#-> Linux
ctrl
+ ' ` ' 在 Windows 上也能完美运行!
CTRL
+`
的问题在于它会创建一个新终端,即使它已经存在。
虽然 VS Code 有很多模式切换和导航快捷方式,但没有一个专门用于“从编辑器移动到终端,然后再返回”。但是,您可以通过重载 key
并使用 when
clause 来组合这两个步骤。
解决方案
您可以通过将适当的设置添加到 keybindings.json
文件来实现所需的效果。以下是所需的步骤:
打开命令面板(Ctrl+Shift+P Windows/Linux 或 ⇧ ⌘ P Mac)。键入“首选项:打开键盘快捷键文件”,然后按 Enter。将以下条目添加到 keybindings.json 文件:
// Toggle between terminal and editor focus
{
"key": "ctrl+`",
"command": "workbench.action.terminal.focus"
},
{
"key": "ctrl+`",
"command": "workbench.action.focusActiveEditorGroup",
"when": "terminalFocus"
}
使用这些快捷键,您可以使用相同的击键在编辑器和集成终端之间集中注意力。
笔记
在现代版本的 VS Code(截至 2022 年)中,默认键盘快捷键 (JSON) 文件是只读,这就是为什么自定义设置,您需要编辑一个单独的专用文件keybindings.json
。
更多信息可以在官方 Visual Studio 文档页面上找到:
Visual Studio Code 的键绑定:高级自定义
ctrl+` : 专注于集成终端
ctrl+1 :专注于编辑器(如果 editor-2 命令是 ctrl+2)
https://i.stack.imgur.com/OubM3.gif
Ctrl+J 有效;但也显示/隐藏控制台。
cmd+J for mac
{ "key": "cmd+j", "command": "workbench.action.terminal.focus"}, { "key": "cmd+j", "command": "workbench.action.focusActiveEditorGroup", "when": "terminalFocus"}
使用已接受答案中的相同技巧,这样我就不必把手从主行移开。
游戏有点晚了,但我在 keybindings.json
中将我的配置如下:
{
"key": "ctrl+`",
"command": "workbench.action.terminal.focus",
"when": "editorTextFocus"
},
{
"key": "ctrl+`",
"command": "workbench.action.focusActiveEditorGroup",
"when": "terminalFocus"
},
{
"key": "alt+`",
"command": "workbench.action.terminal.toggleTerminal"
}
我想要单独的键来打开/关闭终端并在窗口之间来回切换焦点。
alt+`
似乎有问题 - 在 github.com/Microsoft/vscode/issues/41024#issuecomment-363096692 跟踪
alt
比 ctrl
更容易按,所以在我的配置中它是相反的。
alt
来切换焦点。
从版本:1.26.1 (linux) 开始,默认情况下未设置快捷方式。设置快捷方式
打开键盘快捷键面板 [ctrl + k , ctrl + s] 搜索焦点终端
https://i.stack.imgur.com/7Lipk.png
设置快捷方式
默认情况下已经设置了编辑器焦点。
https://i.stack.imgur.com/0vJQT.png
我将我的配置如下,因为我发现 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 上从 System Preferences => keyboard =>Modifier Keys
将 Caps Lock 配置为 ctrl。
另一种选择是使用 F6
和 shift+F6
。
F6
执行“聚焦下一部分”,这会将焦点从编辑器移至下方的 Panel(终端、输出、调试控制台等)。
shift+F6
执行“聚焦上一部分”,这会将焦点从终端面板移回编辑器。
与 ctrl + `
相比,它的优势在于:
它不会隐藏终端/面板(如果这是您喜欢的。如果您喜欢隐藏/取消隐藏终端,那么只需使用 ctrl + `)。这适用于任何面板(终端、输出、调试控制台等)。
嘿,我完成这项工作的步骤是:
ctrl + shift + p 并查找首选项:键盘快捷键
或者您可以使用ctrl k + ctrl s
直接打开它
在搜索框中查找终端:焦点终端,我为自己设置 alt + T alt + T 但您可以选择您想要的组合 在搜索框中查看查看:焦点活动编辑器组,为自己设置 alt + E alt + E 但您可以再次选择您想要的组合
就是这样,希望对你有帮助
根据 VS Code 键盘快捷键 documentation 页面,切换集成终端的默认键绑定是“Ctrl+`”。如果您不喜欢该快捷方式,您可以通过添加类似于以下内容的内容在您的键绑定文件中更改它:
{ "key": "ctrl+l", "command": "workbench.action.terminal.toggleTerminal" }
似乎没有用于简单地聚焦底部面板的默认键绑定。因此,如果您不想切换底部面板,则需要在键绑定文件中添加类似于以下内容的内容:
{ "key": "ctrl+t", "command": "workbench.action.focusPanel" }
focusPanel
适用于一般区域(包括“问题”、“输出”和“调试控制台”等内容。还有一个专门针对集成终端 workbench.action.terminal.focus
的操作。
通常,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"
}
]
ctrl+j
只是切换面板。因此,如果上次使用的面板视图是“问题”,您将跳转到那里而不是终端。此外,ctrl+k
被广泛用作和弦开头,因此覆盖它会破坏很多快捷方式。
这是一种添加您自己的键绑定以切换焦点的方法。
打开你的 VSCode 按 Ctrl+Shift+P 并搜索键盘快捷键并点击它(首选项:打开键盘快捷键)。在搜索面板中搜索“焦点终端”并找到此选项(终端:关注终端视图)并单击加号图标。
https://i.stack.imgur.com/Zb15J.png
输入您喜欢的未使用的快捷方式,然后按 Enter。转到编辑器模式并尝试使用您的快捷方式。现在按 Alt+Shift+T 转到终端。想回到编辑器?只需按 Ctrl+tab
使用 VSCode(1.52.1) 在 Windows 10 机器上测试
尝试使用 ctrl+` 来切换终端的可见性,从而切换焦点。
Shubham Jain 的答案是现在使用内置键盘快捷键的最佳选择。
https://i.stack.imgur.com/PPLin.png
到 Ctrl + ;
https://i.stack.imgur.com/rLRkm.png
到 Ctrl + L
通过这种方式,您可以在终端和编辑器之间移动焦点,并在附近切换终端。
适用于任何键盘布局的简单 WINDOWS 解决方案(可能适用于其他操作系统,但未经测试)
我使用的是芬兰语键盘,所以上述方法都不起作用,但这应该适用于所有键盘。
终端焦点:将鼠标悬停在集成终端中的终端文本上。将弹出专注于终端的快捷方式 - 例如我的说 CTRL+ö。
编辑器焦点:如上所述使用 CTRL+1。
这并不完全是所要求的,但我发现它非常有用且相关。
如果有人想从一个终端切换到另一个终端,也可以在 Visual Studio 的集成终端面板中打开,您可以搜索:
Terminal: Focus Next Terminal
或者添加以下快捷键并使用键盘组合更快地完成。
{
"key": "alt+cmd+right",
"command": "workbench.action.terminal.focusNext",
"when": "terminalFocus"
},
{
"key": "alt+cmd+left",
"command": "workbench.action.terminal.focusPrevious",
"when": "terminalFocus"
},
实际上,在 VS Code 1.48.1 中,有一个 toggleTerminal
命令;我不知道它在以前的版本中是否可用;)您可以在 keybindings.json
文件中使用它。
这在 Windows 上对我有用,也应该在 Linux 上工作。
{
"key": "ctrl+alt+right",
"command": "workbench.action.terminal.toggleTerminal",
"when": "editorTextFocus || terminalFocus"
}
对我的 1.56 VS Code 有用的是:
Ctrl + ~ to focus on terminal window from editor
Ctrl + 9 to focus back on editor from terminal
这是我的方法,它提供了在活动终端之间导航以及在终端和编辑器窗格之间跳转的一致方式无需关闭终端视图。您可以尝试将其直接添加到您的 keybindings.json
,但我建议您通过键绑定 UI(Mac 上的 cmd+K cmd+S
),以便查看/管理冲突等。
有了这个,我可以使用 ctrl+x <arrow direction>
导航到任何可见的编辑器或终端。光标位于终端部分后,您可以使用 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"
},
100% 工作设置...
[
{ "key": "alt+right", "command": "workbench.action.terminal.focus"},
{ "key": "alt+left", "command": "workbench.action.focusActiveEditorGroup", "when": "terminalFocus"}
]
workbench.action.terminal.focus :从编辑器切换到终端。 workbench.action.focusActiveEditorGroup :从终端切换到编辑器。
对于 ctrl+` 组合之间切换,我尝试了所有列出的答案,但没有运气。对于那些与我有类似问题的人,请在 keybindings.json
中尝试以下快捷方式:Tested on VSCode 1.59+
[
{
"key": "ctrl+oem_8","command": "workbench.action.terminal.focus", "when": "!terminalFocus"
},
{
"key": "ctrl+oem_8","command": "workbench.action.focusActiveEditorGroup", "when": "terminalFocus"
}
]
https://i.stack.imgur.com/u4y57.gif
oem_8
就像 OSX 上的冠军一样。其余的规则工作得很好!
我的解决方案:
有一把钥匙
如果还没有终端:打开一个终端并专注于它
如果焦点在终端上:隐藏面板并切换回编辑器
如果焦点在编辑器上并且有一个终端:取消隐藏终端窗格并专注于它
{
"key": "ctrl+shift+alt+cmd+t",
"command": "workbench.action.terminal.new",
"when": "!terminalIsOpen"
},
{
"key": "ctrl+shift+alt+cmd+t",
"command": "terminal.focus",
"when": "terminalIsOpen && !terminalFocus"
},
{
"key": "ctrl+shift+alt+cmd+t",
"command": "workbench.action.closePanel",
"when": "terminalIsOpen && terminalFocus"
}
我通过转到设置>键盘快捷方式然后在它提供搜索栏类型焦点终端的部分并选择该选项来做到这一点。它将要求输入您要为此操作设置的组合。去做吧。至于编辑器焦点类型“编辑器焦点”在搜索栏中并输入您想要的键。如果您出色地添加了密钥。可以通过编辑上面评论中提到的 jason 来删除它
control + '~' 将用于在两者之间切换。 '`' 就在选项卡按钮的上方。此快捷方式仅适用于 mac。
快捷键根据键盘布局(QWERTY/QWERTZ/AZERTA 等)而变化
要找出您的快捷键,请按 Ctrl+Shift+P 并转到首选项:键盘快捷键。
从那里搜索 View:Toggle Terminal
https://i.stack.imgur.com/4nzVA.png
使用 keybindings.json
中的键绑定:
CTRL+j 和 CTRL+k 在编辑器组中的编辑器和终端窗口之间切换焦点
CTRL+h 和 CTRL+l 在包括终端在内的编辑器组之间切换焦点
(vim 用户应该觉得这些键绑定特别自然。其他人可能希望将交换 h/j/k/l
更改为 left/down/up/right
)
// 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"
},
ctrl
+ -
也可以,表示返回上一个光标位置
不定期副业成功案例分享
"ctrl+`"
可以指定为"ctrl+oem_3"
。keybindings.json
文件中。CMD-SHIFT-P
->Preferences: Open Keyboard Shortcuts File
。也是一个不错的资源:code.visualstudio.com/docs/getstarted/keybindings