ChatGPT解决这个技术问题 Extra ChatGPT

Is there a hotkey to switch between split window panes?

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?

what about if I want to split pane but I want the pane/window to do downwards rather than to the side?
Mark the correct answer please, OP
@CharlieParker Shift+Alt+0 toggles between vertical and horizontal editor layouts (workbench.action.toggleEditorGroupLayout)

P
Pieter Meiresone

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.


there actually is a key binding to cycle through opening files. According to this article, It's "CMD + SHIFT + [" and "CMD + SHIFT + ]"
the keys work on Chrome tabs too as I accidentally discovered
Note: For Mac the Ctrl does not work. The key instead of Ctrl is Cmd
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?
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)
D
Dan Andreasson

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

Can't upvote this enough. Thanks!! This is EXACTLY what I was looking for.
Give this guy a raise
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.
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'"
In case you are trying to figure out how to actually edit keybindings.json - see helpful doc here: code.visualstudio.com/docs/getstarted/…
S
Shaun Luttin

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.

Open Visual Studio Code. Go to File > Preferences > Keyboard Shortcuts. Add the following entry to keybindings.json. 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


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!
This Actually answers the question for me. The other answers are for how to navigate between files. Thank you!
Finally, the actual answer!!! At the bottom of the page!
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.
J
Jason Aller

For Mac users and the latest VS Code 1.17:

Switching between panes - Cmd+[1,2,3...], where 1,2,3 is the pane number Cycling between all open files:

forward - Cmd+Shift+]

backwards - Cmd+Shift+[


Oh god, there's no way to differentiate editor panes and tabs when cycling :|
This [Cmd] + [1,2,3...] is what worked for me, on MacOS Catalina.
V
Valdas Stonkus

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


T
Tamás Panyi

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.


Doesn't work in version 1.52+. Ctrl+PgUp/PgDown is used instead
Is there ambushing similar on Mac?
@maks I'm using 1.64.2 (Windows) and Alt+Left / Alt+Right work for me to switch between different panes.
d
dextto

If you mean editor group, here it is.

https://i.stack.imgur.com/zxAQB.png


Yes! I'm so happy this exists now, no more mouse!
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 group
H
Heikki

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

I think those shortcuts are already inside newer versions, and there's also a focusPreviousPane option.
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 + `.
Adding { "key": "alt+up", "command": "workbench.action.focusActiveEditorGroup", "when": "terminalFocus" } to alt+down and removing terminalFocus as explanied by @PhilippeFanaro makes it perfect ;)
I don't know about the new version but my editor did not have his. Switching panes was such a pain. :D Thank you.
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)
C
Charlie Parker

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.


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.
M
Mark Dalsaso

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.


l
lando2319

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


M
Malcolm

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.


V
Vivu

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


I
Isaac Pak

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:

Open up keyboard shortcuts ( Ctrl-k, Ctrl-s ) Do a search for firstEditorGroup and change key binding of workbench.action.focusFirstEditorGroup to ctr-h 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.


m
macquack

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

https://i.stack.imgur.com/4WRcG.png


P
Peter Csala

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

"workbench.action.focusOtherSideEditor"

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.
S
Sagiv Ofek

On Mac:

Move Editor Left    ⌘K←     workbench.action.moveEditorLeftInGroup
Move Editor Right   ⌘K→     workbench.action.moveEditorRightInGroup