193

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?

Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
baldarn
  • 2,842
  • 2
  • 13
  • 13
  • i still to this day avoid using the integrated console. hopefully someone could enlight me with a good workflow – GottZ Jan 25 '18 at 10:31
  • @GottZ I think it's main use for when you are logged in to clusters. How else could you open your files without the integrated console? – gonidelis Oct 13 '20 at 19:19
  • @giannisgonidelis since we are in 2020 now, i agree. the integrated console has evolved beyond xterm.js and is insanely capable now. – GottZ Oct 13 '20 at 20:09

17 Answers17

159

Go to FilePreferencesKeyboard Shortcuts or just press Ctrl + k + Ctrl + s.

Then click the icon in upper right corner, it opens keybindings.json file:

Visual Guide

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

Serhii Popov
  • 3,326
  • 2
  • 25
  • 36
  • 5
    Unfortunately, ```focusNext``` didn't work for me. Instead, ```focusNextPane``` worked like a charm. – squareRoot17 Jun 19 '20 at 06:24
  • 13
    `focusNextPane` works for split terminal, while `focusNext` works for different terminals in the dropdown list – fstang Oct 29 '20 at 10:02
  • 2
    `focusNext` --> `focusNextPane ` and `focusPrevious ` --> `focusPreviousPane` works for me to switch split terminal (left to right, right to left). – vikyd Mar 19 '22 at 14:56
  • It's `pageDown` and `pageUp` (case-sensitive). Tested on Ubuntu 20.04, works great! – WhaSukGO Oct 17 '22 at 09:09
153

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.

Shivam Jha
  • 3,160
  • 3
  • 22
  • 36
  • 6
    You could add the shortcuts to your answer: `workbench.action.terminal.focusNext` `workbench.action.terminal.focusPrevious` and I find even better to remove the `terminalFocus` from the when expression, so you can change terminals without focusing the terminal – phil_lgr May 07 '21 at 20:06
  • 3
    On my international Spanish ISO keyboard, this doesn't seem to work, although if I switch to US Keyboard it does. (Neither works Cmd-AltGr-[ nor Cmd-Shift-AltGr-[ ). It seems to be Ctrl-Option-Cmd-ç – erny Jun 05 '21 at 10:09
  • 2
    Won't work for switching between split terminals, for that you need [@GabrielPetersson's answer](https://stackoverflow.com/a/62941912/1168116) – Malcolm Aug 24 '21 at 18:11
  • I am running VSC on Windows and hitting `Ctrl + PgUp` will just print out `^[[5;5~` characters in my Terminal windows, but thanks for the `Ctrl + Shift + \\` reminder, at least with that shortcut I can switch to the Terminal tabs view and move around with the Up and Down arrow keys and then hitting ENTER to activate the Terminal I want to use next. – GWD Jan 04 '23 at 12:38
  • There's also alt-up and alt-down if you have split terminals – Mathieu Longtin Apr 12 '23 at 18:46
  • Worked for me with no changes needed whatsoever, thanks. – Hakun Jul 04 '23 at 08:47
  • If you don't have `PageUp` and `PageDown` keys on a condensed keyboard, try `fn+up` and `fn+down` – Elijah Mock Aug 31 '23 at 16:16
73

Looking deeply I found it:

{
  "key": "shift+cmd+]",
  "command": "workbench.action.terminal.focusNext",
  "when": "terminalFocus"
}

:)

simhumileco
  • 31,877
  • 16
  • 137
  • 115
baldarn
  • 2,842
  • 2
  • 13
  • 13
59

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
Gabriel Petersson
  • 8,434
  • 4
  • 32
  • 41
35

Improving on @Serhii Popov's answer

Use up and down instead of pageup and pagedown

Go to FilePreferencesKeyboard Shortcuts or just press Ctrl + k + Ctrl + s.

Then click the icon in upper right corner to open the keybindings.json file:

Visual aid

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

Osinachi
  • 656
  • 8
  • 14
  • 1
    I'm not sure this counts as "improving" on their answer. You copy-pasted it and changed one thing. – devrobf Mar 26 '21 at 13:58
  • 1
    Thanks for the answer, I'm on Ubuntu and it had "command": "workbench.action.terminal.focusPreviousPane", need to remove the Pane at the end. – Aindriú May 15 '21 at 19:28
  • Still valid. Thank you. I used alt instead since I remote into windows from a mac most of the day and ctrl+ controls worksapces. – CursedGoat Aug 10 '22 at 19:49
10

On Windows

to switch terminal ctrl + ~

to switch back to code editor ctrl + 1

Yusuf Khan
  • 3,032
  • 3
  • 24
  • 31
9

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

Tomas Zubrik
  • 347
  • 3
  • 11
8

I believe the answer you are looking for is Cmd+Shift+[ (and Cmd+Shift+])

Chris Miller
  • 694
  • 1
  • 12
  • 26
6

I've got Ctrl+PageDown/Ctrl+PageUp in my IDE Keyboard Shortcut settings, which I believe is the default as I didn't change them.

To figure out the shortcuts on your machine, go to File>Preferences>Keyboard Shortcuts and in the search box paste workbench.action.terminal.focusNext or workbench.action.terminal.focusPrevious

This would only switch between terminal groups. So if 2 terminals were in the same group (that is there were split to display side-by-side), it wouldn't switch between those. To switch between terminals in the same group, use "Alt+LeftArrow" or "Alt+RightArrow".

Credits to @Victory Ifebhor for the side-by-side case, clarified in the comments.

Yurii S
  • 315
  • 2
  • 5
  • 1
    This worked for me. I also found that it only switches between terminal groups. So if 2 terminals were in the same group (that is there were split to display side-by-side), it wouldn't switch between those. To switch between terminals in the same group, use "Alt+LeftArrow" or "Alt+RightArrow". – Victory Ifebhor Oct 19 '22 at 17:15
5

Ctrl+J can toggle(show/hide) the console.

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
4

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.

totalhack
  • 2,298
  • 17
  • 23
3

My personal settings to the keybindings.json file that works for me...

Steps:

  1. Press Ctrl + k + s (windows).
  2. Then click the icon in upper right corner, it opens keybindings.json file
  3. Finally paste this code:
[
    {
        "key": "ctrl+win+down",
        "command": "workbench.action.terminal.focusNext",
        "when": "editorIsOpen && terminalHasBeenCreated && terminalIsOpen || terminalFocus && terminalIsOpen && terminalProcessSupported"
    },
    {
        "key": "ctrl+win+up",
        "command": "workbench.action.terminal.focusPrevious",
        "when": "editorIsOpen && terminalHasBeenCreated && terminalIsOpen || terminalFocus && terminalIsOpen && terminalProcessSupported"
    }
]

This settings allows you to switch terminals without having the focus on terminal

Note: You can custom your keyboard shortcut as you want

Alex Bravo
  • 31
  • 3
  • You just made me realize that today, in 2023, on Linux, there are already shortcuts for these commands. Thanks! Ctrl + PgDown and Ctrl + PgUp – richardsonwtr Jul 26 '23 at 16:12
2

Pay attention to the the VS Code concept of Group, as that can trip you up when reading some of the answers here.

i.e there are different default shortcuts to switch between terminals in the same group (CMD+OPT+up/down) or between different terminal groups (SHIFT+CMD+[ / ])

aragalie
  • 175
  • 2
  • 9
  • Thanks for this. For me optimal flow from the editor to terminal is: 'ctrl + `', then 'cmd + opt + up/down', and then to get back to my code 'cmd + 1' (macOS) – Reece Daniels Dec 07 '22 at 11:24
2

If anyone else is so used to switching between tabs with +[0-9] this mapping in your keybindings.json might useful:

  {
    "key": "cmd+1",
    "command": "workbench.action.terminal.focusAtIndex1",
    "when": "terminalFocus"
  },
  {
    "key": "cmd+2",
    "command": "workbench.action.terminal.focusAtIndex2",
    "when": "terminalFocus"
  },
  {
    "key": "cmd+3",
    "command": "workbench.action.terminal.focusAtIndex3",
    "when": "terminalFocus"
  },

You can also extend the conditional in case you're using the terminal editor (to avoid switching when focused).

  {
    "key": "cmd+1",
    "command": "workbench.action.terminal.focusAtIndex1",
    "when": "terminalFocus && !terminalEditorFocus"
  },
wpp
  • 7,093
  • 4
  • 33
  • 65
1

In current version of VSCode it is available like this. You can search this command in the Keyboard Shortcuts

workbench.action.terminal.focusNext

workbench.action.terminal.focusPrevious

enter image description here enter image description here

Rohit Kumar
  • 983
  • 9
  • 11
0

You can set up an easy custom keyboard shortcut in Vs Code for this

  1. You can Ctrl-P and type Keyboard Shortcuts
  2. search for "Terminal: switch active terminal"
  3. set any key combination you want, mine is Ctrl+K since it wasn't used

Now you can switch to focus on the sidebar terminal without using your mouse but if you just want to switch to the main terminal Ctrl+J

Using the Terminal Sidebar

0

I have been trying to find the same shortcut, I found with VS code what helps is to know how the different UI components and actions are called.

In this case once "Keyboard Shortcuts" tab (where you can view and customize shortcuts) is open search for "prev terminal group" or "next terminal group".

We can see that VS Code has default shortcuts for:

  • Terminal: Focus Previous Terminal Group
  • Terminal: Focus Previous Terminal in Terminal Group

See results for my search: enter image description here I am not sure which one you are the most interested in but, try each and once you found the shortcut you were looking for: use it or customize it to your likings.

Hope that helps

athmos
  • 123
  • 1
  • 7