Does anyone know the keyboard shortcut (Mac and Linux) to switch the focus between editor and integrated terminal in Visual Studio Code?
While there are a lot of modal toggles and navigation shortcuts for VS Code, there isn't one specifically for "move from editor to terminal, and back again". However you can compose the two steps by overloading the key
and using the when
clause.
Open the keybindings.json from the editor: CMD-SHIFT-P -> Preferences: Open Keyboard Shortcuts File and add these entries:
// Toggle between terminal and editor focus
{ "key": "ctrl+`", "command": "workbench.action.terminal.focus"},
{ "key": "ctrl+`", "command": "workbench.action.focusActiveEditorGroup", "when": "terminalFocus"}
With these shortcuts I will focus between the editor and the Integrated Terminal using the same keystroke.
control + '~' will work for toggling between the two. and '`' is just above the tab button. This shortcut only works in mac.
A little late to the game but I configured mine as the following in the 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"
}
I wanted separate keys for opening/closing terminal and switching focus back and forth between the windows.
It's not exactly what is asked, but I found it very useful and related.
If someone wants to change from one terminal to another terminal also open in the integrate terminal panel of Visual Studio, you can search for:
Terminal: Focus Next Terminal
Or add the following key shortcut and do it faster with keyboard combination.
{
"key": "alt+cmd+right",
"command": "workbench.action.terminal.focusNext",
"when": "terminalFocus"
},
{
"key": "alt+cmd+left",
"command": "workbench.action.terminal.focusPrevious",
"when": "terminalFocus"
},
ctrl+` : To Focus on Integrated Terminal
ctrl+1 : To Focus on Editor (If editor-2 command would be ctrl+2)
More Info : https://www.rscoder.com/2020/11/14/how-to-switch-focus-between-editor-and-integrated-terminal-in-visual-studio-code/
I configured mine as following since I found ctrl+` is a bit hard to press.
{
"key": "ctrl+k",
"command": "workbench.action.focusActiveEditorGroup",
"when": "terminalFocus"
},
{
"key": "ctrl+j",
"command": "workbench.action.terminal.focus",
"when": "!terminalFocus"
}
I also configured the following to move between editor group.
{
"key": "ctrl+h",
"command": "workbench.action.focusPreviousGroup",
"when": "!terminalFocus"
},
{
"key": "ctrl+l",
"command": "workbench.action.focusNextGroup",
"when": "!terminalFocus"
}
By the way, I configured Caps Lock to ctrl on Mac from the System Preferences => keyboard =>Modifier Keys
.