baldarn
baldarn

Reputation: 3501

How to switch between terminals in Visual Studio Code?

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?

Upvotes: 253

Views: 131785

Answers (21)

Mwiza
Mwiza

Reputation: 9011

Windows and Linux

Alt +

or

Alt +

(Alt + Left Arrow or Alt + Right Arrow)

Mac Os

+ +

or

+ +

(Cmd + Option + Left Arrow or Cmd + Option + Right Arrow)

Further reading: Vscode key bindings.

Upvotes: 2

Руслан Neo
Руслан Neo

Reputation: 11

For MacOS to navigate between splited terminals:

⌥⌘← Previous pane

⌥⌘→ Next pane

Here is the vs code docs

Upvotes: 1

Ravi Misra
Ravi Misra

Reputation: 191

For me, the existing bindings ctrl+` to focus on the terminal panel when in the editor and ctrl+shift+\ to focus on the terminal tabs panel and following custom keybinding ctrl+shift+\ to focus back to the terminal panel when I am on the terminal tab panel, are just enough to skip completely mouse/touchpad while using the vscode.

{
    "key": "ctrl+shift+\\",
    "command": "terminal.focus",
    "when": "terminalHasBeenCreated && terminalTabsFocus && !terminalFocus || terminalProcessSupported && terminalTabsFocus && !terminalFocus"
}

Upvotes: 0

jackie xiao
jackie xiao

Reputation: 1

For MacOs

Move to left terminal - Cmd + Option + LeftArrow
Move to right terminal - Cmd + Option + RightArrow

Move to previous terminal - Ctrl+PageUp (macOS Cmd+Shift+])
Move to next terminal - Ctrl+PageDown (macOS Cmd+shift+[)
Focus terminal tabs view - Ctrl+Shift+\ (macOS Cmd+Shift+)

Upvotes: 0

Alex Bravo
Alex Bravo

Reputation: 51

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

Upvotes: 5

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

Upvotes: 5

wpp
wpp

Reputation: 7323

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"
  },

Upvotes: 3

Rohit Kumar
Rohit Kumar

Reputation: 1341

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

Upvotes: 1

athmos
athmos

Reputation: 163

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 🙏

Upvotes: 0

Yurii S
Yurii S

Reputation: 355

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.

Upvotes: 8

Chris Miller
Chris Miller

Reputation: 763

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

Upvotes: 9

aragalie
aragalie

Reputation: 195

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+[ / ])

Upvotes: 4

William J Priest
William J Priest

Reputation: 41

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

Upvotes: 1

Tomas Zubrik
Tomas Zubrik

Reputation: 507

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

Upvotes: 19

Gabriel Petersson
Gabriel Petersson

Reputation: 10482

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

Upvotes: 64

Shivam Jha
Shivam Jha

Reputation: 4542

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.

Upvotes: 238

Yusuf Khan
Yusuf Khan

Reputation: 4090

On Windows

to switch terminal ctrl + ~

to switch back to code editor ctrl + 1

Upvotes: 17

Osinachi
Osinachi

Reputation: 692

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

Upvotes: 38

Serhii Popov
Serhii Popov

Reputation: 3804

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

Upvotes: 182

totalhack
totalhack

Reputation: 2608

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.

Upvotes: 4

baldarn
baldarn

Reputation: 3501

Looking deeply I found it:

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

:)

Upvotes: 79

Related Questions