Is there a hotkey to switch between split window panes?
Asked Answered
G

20

421

Visual Studio Code has a hotkey combination to split the current window to 2 or 3 panes:

"key": "ctrl + \",               "command": "workbench.action.splitEditor"

Unfortunately, I can't find a way to switch between such panes without the mouse. My old habit to use F6 does not work either.

Is it supported in Visual Studio Code editor or not?

Goldeye answered 31/3, 2016 at 8:28 Comment(3)
what about if I want to split pane but I want the pane/window to do downwards rather than to the side?Mushro
Mark the correct answer please, OPJeannajeanne
@CharlieParker Shift+Alt+0 toggles between vertical and horizontal editor layouts (workbench.action.toggleEditorGroupLayout)Karynkaryo
G
576

https://code.visualstudio.com/docs/customization/keybindings#_editorwindow-management

For Windows: Ctrl+1, Ctrl+2 and Ctrl+3.

For Mac: Cmd+1, Cmd+2 and Cmd+3.

There is no circular switch between panes, similar to what Ctrl+tabs does for files, though.

Goldeye answered 31/3, 2016 at 8:30 Comment(10)
there actually is a key binding to cycle through opening files. According to this article, It's "CMD + SHIFT + [" and "CMD + SHIFT + ]"Neuburger
the keys work on Chrome tabs too as I accidentally discoveredDietetics
Note: For Mac the Ctrl does not work. The key instead of Ctrl is CmdRejoinder
why would you use ctrl+1 if "CMD + SHIFT + [" and "CMD + SHIFT + ]" exists?Mushro
Ctrl + Shift + [ / ] seems to be mapped to code folding and unfolding in my version (1.46). I never changed the defaults.Does this mean they changed the defaults?Reticent
@Neuburger the key binding you showed cycles through tabs in one pane, but the question is about cycling trough panesPastis
This isn't true, as Shaun Luttin shows below, the action you're looking for is workbench.action.navigateEditorGroups (can be found in Keyboard shortcuts by searching or in associated json)Gollin
You can easily modify ctrl+tab to switch between files and panes (see my answer)Karynkaryo
CTRL/CMD + SHIFT + [ switches between tabs on the same pane, so if you have multiple files open on a pane, it can be annoying to cycle through all of them. To only switch between panes, it is much faster to use CTRL/CMD + 1/2/3/etcConsequent
In the current Mac version, it uses ctrl-1 instead of cmd-1. Not sure when this changed...Eumenides
B
446

If you're used to working in vim (and/or tmux) and want to move around with ctrl+hjkl

add these to keybindings.json

[
    {
        "key": "ctrl+h",
        "command": "workbench.action.navigateLeft"
    },
    {
        "key": "ctrl+l",
        "command": "workbench.action.navigateRight"
    },
    {
        "key": "ctrl+k",
        "command": "workbench.action.navigateUp"
    },
    {
        "key": "ctrl+j",
        "command": "workbench.action.navigateDown"
    }
]
Base answered 29/5, 2018 at 21:23 Comment(12)
Thank you for this. I had already searched through the keybindings without any luck. It seems like the terms "focus" and "navigate" aren't consistently used.Khalilahkhalin
Thanks for this! In case it helps anyone, I just discovered it breaks VsCodeVim's Ctrl+x line completion (probably amongst other things) so it felt sensible to disable these shortcuts in insert mode: "when": "vim.mode != 'Insert'"Amplitude
In case you are trying to figure out how to actually edit keybindings.json - see helpful doc here: code.visualstudio.com/docs/getstarted/…Copal
@EmilioBool interesting enough, this suggestion does not let one (at least for me) cycle between left/right terminals like workbench.action.terminal.focusNextPane allows. Yet it allows to cycle up and down between "code" and terminal panes.Pongid
This is nearly perfect, but for example I can't go from the "Find" text field to the search results with <C-j>. I made my own config that can do this and a couple of more things (like using <C-j/k> to cycle through IntelliSense suggestions). lmk if anybody's interestedNarrowminded
this is what i need. FYI might be worth adding for Mac, replace control with cmdThough
@Pongid same here. Would be very cool if it would work with split terminals as well. Does somebody know how to incorporate this?Coffeng
This is a great addition, don't get me wrong, and sorry to be pedantic, but... it's not actually the correct answer! @Goldeye has the correct answer with the cmd/ctrl+1 etc shortcuts that come out of the box. This answer is very helpful and I will use it myself, but if it gets voted higher than then other one, which has almost happened, it risks obscuring the real answer which people who aren't familiar with vi or tmux could miss... this a problem with stackoverlflow, not the answer. One for SO meta?Gibe
Thanks for your excellent answer. I personally use a variation on this to replicate my tmux/vim setup, with a ctrl + space default prefix in tmux. Simple difference: map the above to their respective ctrl + space + [h, j, k, l] chord. Then press ctrl + space and your movement key. Kind of gives a vim-like mode for moving around.Westfall
This clobbers several default shortcuts, especially the default chord ctrl+k!Karynkaryo
works for me, but I have to double tap h j k and l for some reason !! ¯\_(ツ)_/¯Dermatome
Add "when": "editorTextFocus" to avoid some possible conflicts with other keybindings.Leena
B
165

Use F6 to Cycle Between Editor Groups

There is a circular switch between panes. It's called "Cycle Between Editor Groups."

Out of the box, it is unassigned. We can assign it to F6.

  1. Open Visual Studio Code.
  2. Go to File > Preferences > Keyboard Shortcuts.
  3. Add the following entry to keybindings.json.
  4. You do not have to restart code. It already works.

keybindings.json

// Place your key bindings in this file to overwrite the defaults
[
    {
        "key": "f6", 
        "command": "workbench.action.navigateEditorGroups" 
    }
]

Alternatively

Alternatively, use the out of the box window management hotkeys.

  • Ctrl +1 Focus into Left Editor Group
  • Ctrl +2 Focus into Side Editor Group
  • Ctrl +3 Focus into Right Editor Group
  • Ctrl +K Ctrl+Left Focus into Editor Group on the Left
  • Ctrl +K Ctrl+Right Focus into Editor Group on the Right
Bartko answered 15/8, 2016 at 23:21 Comment(5)
Wow, thanks you, I accidentally found something I've been looking for. Ctrl + K + Left (notice no Ctrl on the Left) does View: Move Editor Group Left (workbench.action.moveActiveEditorGroupLeft). Thank you!Subtend
This Actually answers the question for me. The other answers are for how to navigate between files. Thank you!Grecize
Finally, the actual answer!!! At the bottom of the page!Buskin
In VSCode (v1.64) F6 is already assigned to the command that switches between "parts", which is also useful, so I did Shift+W instead.Illogic
Ctrl+1, and Ctrl+2 worked for me. thanks!Constraint
E
74

For Mac users and the latest VS Code 1.17:

  1. Switching between panes - Cmd+[1,2,3...], where 1,2,3 is the pane number
  2. Cycling between all open files:
  • forward - Cmd+Shift+]
  • backwards - Cmd+Shift+[
Evelinevelina answered 12/10, 2017 at 15:51 Comment(2)
Oh god, there's no way to differentiate editor panes and tabs when cycling :|Dagmar
This [Cmd] + [1,2,3...] is what worked for me, on MacOS Catalina.Charlotte
S
34

Another way is to use Ctrl + PageUp/PageDow to switch between panes.

Shaniceshanie answered 2/12, 2018 at 18:2 Comment(0)
N
32

Alt+ and Alt+ works out of the box on Windows. It will only switch between split screen panes and it will not reactivate inactive files inside the panes.

Nalepka answered 23/7, 2018 at 10:42 Comment(3)
Doesn't work in version 1.52+. Ctrl+PgUp/PgDown is used insteadBouillon
Is there ambushing similar on Mac?Nameplate
@Bouillon I'm using 1.64.2 (Windows) and Alt+Left / Alt+Right work for me to switch between different panes.Impudence
E
21

If you mean editor group, here it is.

enter image description here

Elgar answered 23/4, 2020 at 22:14 Comment(2)
Yes! I'm so happy this exists now, no more mouse!Jiggermast
This should be the most correct answer. As with what @duane mentioned in a comment to another answer, cmd+Left/Right goes to the next panel regardless if it's another tab in the same or a different editor groupPsittacine
H
9

What you are looking for is option workbench.action.terminal.focusNextPane:

{ 
  "key": "alt+down",
  "command": "workbench.action.terminal.focusNextPane",
  "when": "terminalFocus"
},
{ 
  "key": "alt+right",
  "command": "workbench.action.terminal.focusNextPane",
  "when": "terminalFocus"
},
Hostel answered 8/2, 2019 at 10:27 Comment(5)
I think those shortcuts are already inside newer versions, and there's also a focusPreviousPane option.Marnamarne
Personally, I don't even use the "when": "terminalFocus" specification, it makes managing the terminals quicker because I don't have to add a shortcut like Ctrl + `.Marnamarne
Adding { "key": "alt+up", "command": "workbench.action.focusActiveEditorGroup", "when": "terminalFocus" } to alt+down and removing terminalFocus as explanied by @PhilippeFanaro makes it perfect ;)Hawker
I don't know about the new version but my editor did not have his. Switching panes was such a pain. :D Thank you.Propositus
My VS Code has these settings by default but when I use them the cursor moves to next pane but as soon as I release the alt key the focus is lost and the menu bar gets focused instead (the bar with file, edit, selection, view, go etc, etc... options on the very top)Idalia
M
8

Obviously the best answer is the hidden comment on the top answer. Not sure why there isn't an answer for it:

CMD + SHIFT + [

and

CMD + SHIFT + ]

I am not sure why anyone would use cmd + 1 or its variants.

Mushro answered 24/1, 2020 at 19:56 Comment(1)
You'd use cmd + 1 or it's other variants (2, 3, 4, etc) because that's how most tabbed applications work. CMD + SHIFT + ] treats all the panes like they are sibling tabs on the same window.Tranquillize
H
8

I recently found this key binding which switch focus between split panes in group.

"workbench.action.focusOtherSideEditor"
Handal answered 14/1, 2022 at 17:3 Comment(2)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Clayton
Thank you so much for this! I've been looking for this setting forever. This allows for switching between editors when they are within the same tab (E.g. when viewing file diffs, or when splitting an editor with "workbench.action.splitEditorInGroup")Albano
U
6

Yes, there is a hotkey to switch between split "editor" window panes, if that is what you mean.

It has to be configured though. This is because the command that allows cycling thru editor panes (aka editor groups) has no default keyboard mapping/binding. Open the "Keyboard Shortcuts" menu option and search for workbench.action.navigateEditorGroups . Click the + icon to add/assign a keybinding. I mapped it to Alt+Q because on a qwerty keyboard 'q' is right next to the Tab key. Given that Alt+Tab cycles thru open OS Windows, it seems sort of natural there.

Unclose answered 21/11, 2018 at 17:52 Comment(0)
F
5

cmd + option + Left/Right Arrows worked for me.

Fridell answered 1/8, 2020 at 13:1 Comment(0)
K
4

By default, Ctrl+Tab cycles through editors in the current group, but not between groups. We can simply extend the default shortcut to get the behavior we want. The VS Code user guide tells us what we need to add to our keybindings.json:

[
  {
    "key": "ctrl+tab",
    "command": "workbench.action.quickOpenPreviousRecentlyUsedEditor",
    "when": "!inEditorsPicker"
  },
  {
    "key": "ctrl+shift+tab",
    "command": "workbench.action.quickOpenLeastRecentlyUsedEditor",
    "when": "!inEditorsPicker"
  }
]

This will modify Ctrl+Tab to cycle through all open editors, not just the ones in the current group.

While it won't directly switch between groups, I prefer this solution since it combines both types of navigation (moving between groups, moving between editors) into a single shortcut that is already in my muscle memory.

Karynkaryo answered 26/8, 2021 at 18:25 Comment(2)
Slightly unrelated but CTRL + TAB is one of the hardest combination to press even with large hands. CTRL + SHIFT + TAB makes it worse. Granted, a different combination could be used of course.Coquet
@Coquet The main advantage of this key combination is that people who are already using it in other applications--to switch between tabs in their browser, for example--don't have to learn a new key combination to perform essentially the same action. I admit it is a bit awkward on standard keyboards.Karynkaryo
D
4

On Mac:

Move Editor Left    ⌘K←     workbench.action.moveEditorLeftInGroup
Move Editor Right   ⌘K→     workbench.action.moveEditorRightInGroup
Dagney answered 7/6, 2022 at 2:3 Comment(1)
Note this flips the right and the left panels. I think the OP was aiming for cycling between left and right panels => moving the active cursor from one to the otherFarlie
S
4

If you want to switch between editor groups (on *nix systems):

  • switch to left: ctrl + K ctrl + leftArrow,
  • switch to right: ctrl + K ctrl + rightArrow,
  • switch to up: ctrl + K ctrl + upArrow,
  • switch to down: ctrl + K ctrl + downArrow.

You can also switch between them using ctrl + [1, 2, 3, ...] (starts from left group).

Selenium answered 14/3, 2023 at 8:52 Comment(0)
G
3

What you are looking for is: view: focus next editor group

I defined ctrl+H for this shortcut! That's all!

focus next editor group

furthermore, This key binding works as well:

workbench.action.navigateEditorGroups

Gonzales answered 10/9, 2022 at 4:32 Comment(1)
Why would you set Ctrl+H, this is the common command for find & relace in so many tools.Obregon
D
3

To supplement @DanAndreasson's great answer, if you'd like to get the benefit of navigating split terminal panes, try adding this:

  {
    "key": "ctrl+h",
    "command": "workbench.action.terminal.focusPreviousPane",
    "when": "terminalFocus"
  },
  {
    "key": "ctrl+l",
    "command": "workbench.action.terminal.focusNextPane",
    "when": "terminalFocus"
  }

And if you want navigation between editor groups to behave similarly to the terminal pane focus, replace

  {
    "key": "ctrl+h",
    "command": "workbench.action.navigateLeft"
  },
  {
    "key": "ctrl+l",
    "command": "workbench.action.navigateRight"
  }

with

  {
    "key": "ctrl+h",
    "command": "workbench.action.focusPreviousGroup"
  },
  {
    "key": "ctrl+l",
    "command": "workbench.action.focusNextGroup"
  }

It's worth noting that you lose navigation to the sidebar with the group focus replacement if that's important to you.

Doehne answered 28/2, 2023 at 0:36 Comment(1)
focusNextGroup focusPreviousGroup works great on Mac!Coquet
L
2

Try Option+Tab for switching sequentially, Cmd+ for switching by number and shift+cmd+[ (or ]) switches between tabs across editors

Lotze answered 31/8, 2020 at 7:22 Comment(0)
C
2

If none of the above worked for you and you want just a simple ctrl-h to bind to the left pane and ctrl-l to bind to the right pane then do this:

  1. Open up keyboard shortcuts ( Ctrl-k, Ctrl-s )

  2. Do a search for firstEditorGroup and change key binding of workbench.action.focusFirstEditorGroup to ctr-h

  3. Do another search for secondEditorGroup and change key binding of workbench.action.focusSecondEditorGroup to ctr-h

This is a simple setup if you only ever have two editor panes up.

Corregidor answered 10/2, 2021 at 19:59 Comment(0)
A
2

The command View: Navigate Between Editor Groups worked for me, on the MacOS version (1.54.3).

Keyboard shorcut

Adelinaadelind answered 21/3, 2021 at 12:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.