How to use predefined layouts in tmux?

Quick Answer

tmux offers five built-in window layouts: even-horizontal, even-vertical, main-horizontal, main-vertical, and tiled. To change layouts, press Ctrl+b Space to cycle through them, or use Ctrl+b : select-layout layout-name to choose a specific layout. You can also create custom layouts using select-layout -E to evenly size panes or manually adjust pane sizes with Ctrl+b Alt+arrow keys.

# Cycle through layouts
Ctrl+b Space

# Select specific layout
Ctrl+b :select-layout even-horizontal

Detailed Explanation

tmux layouts determine how multiple panes are arranged within a window. Understanding and manipulating these layouts can significantly improve your workflow efficiency, especially when working with multiple commands or tasks simultaneously.

Built-in Layout Types

tmux provides five standard layouts:

  • even-horizontal - All panes are arranged side by side, with equal width
  • even-vertical - All panes are stacked on top of each other, with equal height
  • main-horizontal - One large pane on top, with smaller panes arranged horizontally below it
  • main-vertical - One large pane on the left, with smaller panes arranged vertically to the right
  • tiled - All panes are arranged to use the available space as efficiently as possible, with roughly equal size

Cycling Through Layouts

The quickest way to change layouts is to cycle through them:

# Cycle through all layouts
Ctrl+b Space

Each press will switch to the next layout in the sequence, allowing you to quickly find the arrangement that works best for your current task.

Selecting a Specific Layout

To switch directly to a specific layout:

# In tmux command mode (Ctrl+b :)
select-layout even-horizontal
select-layout even-vertical
select-layout main-horizontal
select-layout main-vertical
select-layout tiled

Adjusting the Main Pane

For the main-horizontal and main-vertical layouts, you can adjust the size of the main pane:

# Increase main pane height (for main-horizontal)
Ctrl+b :resize-pane -D 10

# Increase main pane width (for main-vertical)
Ctrl+b :resize-pane -R 10

You can also set the number of panes to show in the main area:

# Set how many panes to show in the main area
Ctrl+b :set-window-option main-pane-height 20
Ctrl+b :set-window-option main-pane-width 100

Manual Resizing

You can manually resize panes using these key combinations:

  • Ctrl+b Alt+Up - Increase current pane height
  • Ctrl+b Alt+Down - Decrease current pane height
  • Ctrl+b Alt+Left - Decrease current pane width
  • Ctrl+b Alt+Right - Increase current pane width

For more precise control, you can use the command mode:

# Resize the current pane down by 10 cells
Ctrl+b :resize-pane -D 10

# Resize the current pane up by 10 cells
Ctrl+b :resize-pane -U 10

# Resize the current pane left by 10 cells
Ctrl+b :resize-pane -L 10

# Resize the current pane right by 10 cells
Ctrl+b :resize-pane -R 10

Creating Custom Layouts

You can create custom layouts by arranging panes as desired and then saving the layout:

# First, arrange your panes the way you want them
# Then, save the current layout
Ctrl+b :select-layout -E  # This evenly spaces the current layout

# To save the layout for later use
Ctrl+b :run-shell "tmux list-windows -F \"#{window_layout}\" > ~/.tmux-layout"

To restore a saved layout:

# From your saved layout file
Ctrl+b :run-shell "tmux select-layout \"$(cat ~/.tmux-layout)\""

Spreading Panes Evenly

After manually resizing panes, you can redistribute them evenly:

# Make all panes equally sized while preserving arrangement
Ctrl+b :select-layout -E

Pro Tip

Create custom key bindings for your favorite layouts:

# Add to ~/.tmux.conf
# Horizontal split layout
bind-key H select-layout even-horizontal

# Vertical split layout
bind-key V select-layout even-vertical

# Main programming layout (large left pane, two right panes)
bind-key P select-layout main-vertical \; resize-pane -t 0 -x 120

This configuration lets you quickly switch between common layouts with Ctrl+b H, Ctrl+b V, and Ctrl+b P.