How to switch between terminals in Visual Studio Code?
Visual Studio-CodeTerminalIdeEditorKeyboard ShortcutsVisual Studio-Code Problem Overview
I'm looking to switch between terminals open in visual studio code.
With this "Switch focus between editor and integrated terminal in Visual Studio Code" question I correctly setup the focus, but I would like to switch between terminals, not only from code to terminal.
Is there a way to do it?
Visual Studio-Code Solutions
Solution 1 - Visual Studio-Code
Go to File → Preferences → Keyboard Shortcuts or just press Ctrl + k + Ctrl + s.
Then click the icon in upper right corner, it opens keybindings.json
file:
Try adding the following two entries to this file:
{
"key": "ctrl+pagedown",
"command": "workbench.action.terminal.focusNext",
"when": "terminalFocus"
},
{
"key": "ctrl+pageup",
"command": "workbench.action.terminal.focusPrevious",
"when": "terminalFocus"
}
> Note: On Mac change ctrl to cmd
Solution 2 - Visual Studio-Code
Looking deeply I found it:
{
"key": "shift+cmd+]",
"command": "workbench.action.terminal.focusNext",
"when": "terminalFocus"
}
:)
Solution 3 - Visual Studio-Code
As of Release 1.56.0, there is inbuilt support for switching terminals in VS Code:
> New keybindings
>
> The terminal has several new default keybindings this release:
>
> 1. Move to previous terminal - Ctrl+PageUp (macOS Cmd+Shift+])
> 2. Move to next terminal - Ctrl+PageDown (macOS Cmd+shift+[)
> 3. Focus terminal tabs view - Ctrl+Shift+\ (macOS Cmd+Shift+\)
- Terminal tabs preview
>
> As always, these default keybindings can be removed or custom
> keybindings can be added via the keybindings system.
Solution 4 - Visual Studio-Code
alt
+ up/down left/right arrows
to switch between splitted terminals.
If alt
unfocuses your terminal and focuses the menu, add this to the settings file
// settings.json
"window.titleBarStyle": "custom",
"window.customMenuBarAltFocus": false
Solution 5 - Visual Studio-Code
Improving on @Serhii Popov's answer
Use up and down instead of pageup and pagedown
Go to File
→ Preferences
→ Keyboard Shortcuts
or just press Ctrl + k + Ctrl + s.
Then click the icon in upper right corner to open the keybindings.json file:
Then add the objects below to the array in the file:
[ ... { "key": "ctrl+down", "command": "workbench.action.terminal.focusNext", "when": "terminalFocus" }, { "key": "ctrl+up", "command": "workbench.action.terminal.focusPrevious", "when": "terminalFocus" } ...]
Note: On Mac change ctrl
to cmd
Solution 6 - Visual Studio-Code
On Windows
to switch terminal ctrl
+ ~
to switch back to code editor ctrl
+ 1
Solution 7 - Visual Studio-Code
On Windows 10 (not sure about Linux and Mac):
To switch between split terminal windows in Visual Studio Code use
> Alt + Right arrow / Left arrow
Solution 8 - Visual Studio-Code
Here is my approach, which provides a consistent way of navigating between active terminals as well as jumping between the terminal and editor panes. 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 (note that moving between on-screen split terminals is done with ctrl+x left
or ctrl+x right
).
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"
},
This is a work in progress as I'm trying to mimic my emacs behavior in VS Code, but some key elements are missing, like being able to navigate to a terminal buffer by name (without using a mouse/dropdown). Overall I'm pretty surprised by the poor editor group/pane navigation UX in an otherwise amazing product, but working on getting used to it.
Solution 9 - Visual Studio-Code
Ctrl+J can toggle(show/hide) the console.