194

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?

3
  • i still to this day avoid using the integrated console. hopefully someone could enlight me with a good workflow
    – GottZ
    Jan 25, 2018 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, 2020 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, 2020 at 20:09

17 Answers 17

160

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

4
  • 5
    Unfortunately, focusNext didn't work for me. Instead, focusNextPane worked like a charm. Jun 19, 2020 at 6:24
  • 13
    focusNextPane works for split terminal, while focusNext works for different terminals in the dropdown list
    – fstang
    Oct 29, 2020 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, 2022 at 14:56
  • It's pageDown and pageUp (case-sensitive). Tested on Ubuntu 20.04, works great!
    – WhaSukGO
    Oct 17, 2022 at 9:09
155

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.

7
  • 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 7, 2021 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 5, 2021 at 10:09
  • 2
    Won't work for switching between split terminals, for that you need @GabrielPetersson's answer
    – Malcolm
    Aug 24, 2021 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 4 at 12:38
  • There's also alt-up and alt-down if you have split terminals Apr 12 at 18:46
74

Looking deeply I found it:

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

:)

3
  • 6
    where do u add this? settings.json ? Apr 30, 2020 at 22:14
  • 2
    To add that go to File > Preferences > Keyboard Shortcuts. Then Open 'keybindings.json'. Basically, the answer below by @Serhii is the right procedure
    – ewalel
    Aug 29, 2020 at 8:39
  • 1
    For windows user "key": "shift+ctrl+]" @baldam thanks. It worked as expected.
    – rajakvk
    Dec 12, 2020 at 5:17
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
3
  • 2
    you might also need to press alt to gain focus Dec 6, 2020 at 15:12
  • This solution did not work for me on unix. However @badran's did: shift + cmd + ]
    – rsmets
    Jul 7, 2021 at 15:34
  • Nvm found the alt unfocus problem, added solution Nov 29, 2021 at 14:59
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

3
  • 1
    I'm not sure this counts as "improving" on their answer. You copy-pasted it and changed one thing.
    – devrobf
    Mar 26, 2021 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, 2021 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+<any arrow> controls worksapces.
    – CursedGoat
    Aug 10, 2022 at 19:49
11

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

2
  • 6
    In Mac, it's CMD + Alt + Arrow Keys Mar 18, 2022 at 17:18
  • 2
    you can also use Alt + Up / Down arrow :)
    – starriet
    Apr 19, 2022 at 2:48
10

On Windows

to switch terminal ctrl + ~

to switch back to code editor ctrl + 1

2
  • 1
    the most underrated anwser
    – mati kepa
    May 2, 2022 at 19:59
  • For windows, this should be the exact answer. Thanks!
    – mshsayem
    May 20, 2022 at 9:00
8

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

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.

1
  • 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". Oct 19, 2022 at 17:15
5

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

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.

3

Best personal settings to the keybindings.json file to solve it...

Steps:

  1. Press Ctrl + k + s.
  2. Then click the icon in upper right corner, it opens keybindings.json file enter image description here
  3. Finally paste one of this codes:

On windows ⊞ Win

[
    {
        "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"
    }
]

On Linux Meta

[
    {
        "key": "ctrl+meta+down",
        "command": "workbench.action.terminal.focusNext",
        "when": "editorIsOpen && terminalHasBeenCreated && terminalIsOpen || terminalFocus && terminalIsOpen && terminalProcessSupported"
    },
    {
        "key": "ctrl+meta+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

1
  • You just made me realize that today, in 2023, on Linux, there are already shortcuts for these commands. Thanks! Ctrl + PgDown and Ctrl + PgUp Jul 26 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+[ / ])

1
  • 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) Dec 7, 2022 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"
  },
0
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

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 🙏

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.