298

I'm looking for a behavior that is similar to how vim(1) handles its split windows with ^w =. I know tmux(1) has predefined layouts with ^b Meta[1-5], but this likely does not have the layout that I am currently using.

When splitting a window, it halves the current window for both panes. Split again, and it halves that pane into two new. Combine vertical and horizontal splits, and they continue to halve each other, each new pane getting smaller and smaller.

How can I keep the new layout I've just created, but have all vertical and horizontal splits equally balanced, like vim(1) does with ^w =?

2
  • The description for the "tiled" layout says "Panes are spread out as evenly as possible over the window in both rows and columns." Could you explain how what you want is different from this please? Feb 29, 2012 at 18:56
  • 1
    Sure. This describes it very well: gist.github.com/1942422 Mar 2, 2012 at 19:39

7 Answers 7

414

Vertically

select-layout even-vertical
Usually assigned to: Ctrl+b, Alt+2

Horizontally

select-layout even-horizontal
Usually assigned to: Ctrl+b, Alt+1

10
  • 81
    For other people who are wondering: C-b M-2 means Control-b, and M-2 means alt+2. Jun 21, 2014 at 20:49
  • 37
    M-2 means ESC+2 for me on Debian using Gnome Terminal. Probably depends on setup.
    – arcyqwerty
    Nov 24, 2014 at 5:06
  • 9
    C-... and M-... are emacs-ims M- means "meta" which is [Alt] in combination with or [Esc] followed by the referenced key both options look the same over the wire, but there is the possibility that your GUI may be trapping the [Alt] sequence
    – Jasen
    Jul 17, 2015 at 3:56
  • 9
    Just to put this here in case it helps someone else, because I am constantly confused, "vertical" and "horizontal" are the direction of the spacing--that is, choosing even-vertical will create a layout where the three panes are stacked vertically, equal in height, where even-horizontal will create a layout where the three panes are side-by-side, equal in width
    – A. Wilson
    Mar 22, 2016 at 16:20
  • 1
    How to do M-2 on macOS with a keyboard where "2" requires pressing shift (like the French keyboard)? I didn't succeed, with various combinations of alt, control, command, escape and shift + 2… Apr 7, 2018 at 9:05
137

You can use ctrl-b space to cycle through layouts with even spacing, but that won't necessarily preserve the layout you had.

4
  • 3
    The idea behind the trick (if you want to map it to something else or adapt it): bind-key -r Space next-layout. Then C-b Space Space Space...
    – BenC
    Nov 24, 2014 at 14:01
  • 4
    Is there a way to know which layout I've selected, and how to quickly jump to it again?
    – hughes
    Apr 16, 2015 at 21:15
  • this is a nice one, let you explore various combinations
    – emvidi
    Feb 11, 2021 at 20:34
  • very useful and easy to remember!
    – supersan
    Oct 29, 2021 at 12:16
35

From the command line you can use

tmux select-layout tiled

to make your splits all roughly equal size. You can bind that to a key command as well.

1
  • 6
    Usually assigned to: C-b M-5
    – minipif
    Jan 17, 2018 at 3:40
7

I don't know any single key shortcut, but maybe this helps you:

You can try to write some script to do the layout, and bind a key to the script. You can do this by using tmuxcommand pipe-pane [-o] [-t target-pane] [shell-command] to write the current layout to the script. Next you need to read a layout prepared by the script using tmuxcommand select-layout .

3

ctrl b and then :resize-pane -M and then just use your mouse! (requires mouse-mode to be enabled)

1
  • 2
    mice do not belong in terminals
    – inetknght
    Mar 23, 2021 at 20:49
2

I was having a hard time finding the magic incantation to split into 4 equal quadrants, so here it is:

# Split session into FOUR EQUAL quadrants
tmux selectp -t 0    # select the first (0) pane
tmux splitw -h -p 50 # split it into two halves
tmux selectp -t 0    # select the first (0) pane
tmux splitw -v -p 50 # split it into two halves

tmux selectp -t 2    # select the new, second (2) pane
tmux splitw -v -p 50 # split it into two halves
tmux selectp -t 0    # go back to the first pane
1

tmux provides with some pre defined layouts, do tmux select-layout and you will have some options:

even-horizontal even-vertical main-horizontal main-vertical tiled

1
  • Perhaps you could explain what the different layouts do, and how they address the original question (in ways that haven’t already been covered). Nov 18, 2021 at 17:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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