Does anyone know the keyboard shortcut (Mac and Linux) to switch the focus between editor and integrated terminal in Visual Studio Code?
19 Answers
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.
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.
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
.
The default keybinding to toggle the integrated terminal is "Ctrl+`" according to VS Code keyboard shortcuts documentation page. If you don't like that shortcut you can change it in your keybindings file by adding something similar to:
{ "key": "ctrl+l", "command": "workbench.action.terminal.toggleTerminal" }
There does not seem to be a default keybinding for simply focusing the bottom panel. So, if you do not want to toggle the bottom panel, you will need to add something similar to the following to your keybindings file:
{ "key": "ctrl+t", "command": "workbench.action.focusPanel" }
Generally, VS Code uses ctrl+j
to open Terminal, so I created a keybinding to switch with ctrl+k
combination, like below at keybindings.json
:
[
{
"key": "ctrl+k",
"command": "workbench.action.terminal.focus"
},
{
"key": "ctrl+k",
"command": "workbench.action.focusActiveEditorGroup",
"when": "terminalFocus"
}
]
Hey my steps to make this work were:
ctrl + shift+ p
and look forpreferences: keyboard shortcuts
or you can use ctrl k + ctrl s
to open it directly
Look in the search box for
Terminal: Focus Terminal
, I set up for myselfalt + T alt + T
but you can select the combination that you wantLook in the search box for
View: Focus Active Editor Group
, set up for myselfalt + E alt + E
but again you can select the combination that you want
That's it, I hope this help
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"
},
SIMPLE WINDOWS SOLUTION FOR ANY KEYBOARD LAYOUT (may work for other OS but not tested)
I use a Finnish keyboard so none of the above worked but this should work for all keyboards.
- Terminal focus: Hover your mouse over the terminal text in the integrated terminal. The shortcut for focusing on the terminal will pop up - mine for example said CTRL+ö.
- Editor focus: as mentioned above use CTRL+1.
Actually, in VS Code 1.48.1, there is a toggleTerminal
command; I don't know if it was available in previous versions ;) You can utilize it in the keybindings.json
file.
This worked for me on Windows, and should also works on Linux.
{
"key": "ctrl+alt+right",
"command": "workbench.action.terminal.toggleTerminal",
"when": "editorTextFocus || terminalFocus"
}
Here is a way to add your own keybinding for switching focus.
- Open your VSCode
- Press
Ctrl+Shift+P
and search for keyboard shortcuts and hit this (Preferences: Open Keyboard shortcuts). - Search for 'focus terminal' in the search panel and find this option (Terminal: Focus on Terminal View) and click on the plus icon.
- Enter the shortcut as you like which is not used and hit Enter.
- Go to Editor mode and try using your shortcut.
- Now hit
Alt+Shift+T
to go to the terminal. - Want to go back to the editor? Just Hit
Ctrl+tab
Tested on Windows 10 machine with VSCode(1.52.1)
Here is my approach, which provides a consistent way of navigating between active terminals as well as jumping between the terminal and editor panes without closing the terminal view. You can try adding this to your keybindings.json
directly but I would recommend you go through the keybinding UI (cmd+K cmd+S
on a Mac) so you can review/manage conflicts etc.
With this I can use ctrl+x <arrow direction>
to navigate to any visible editor or terminal. Once the cursor is in the terminal section you can use ctrl+x ctrl+up
or ctrl+x ctrl+down
to cycle through the active terminals.
cmd-J
is still used to hide/show the terminal pane.
{
"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"
},
I did this by going to setting>Keyboard Shortcuts then in the section where it give a search bar type focus terminal and select the option. It will ask to type the combination which you want to set for this action. DO it. As for editor focus type" editor focus" in the search bar and type your desired key. IF you excellently add a key . it can be removed by going to edit jason as mentioned in above comments
100% Working Settings...
[
{ "key": "alt+right", "command": "workbench.action.terminal.focus"},
{ "key": "alt+left", "command": "workbench.action.focusActiveEditorGroup", "when": "terminalFocus"}
]
workbench.action.terminal.focus : To switch from editor to terminal. workbench.action.focusActiveEditorGroup : To switch from terminal to editor.
ctrl
+ ' ` ' will be the best#-> Linux
– muthukumar selvarajctrl
+ ' ` ' works with Windows flawlessly too! – Ehtesham ZCTRL
+`
is that it creates a new terminal even if one already exists. – Guss