tmux Cheatsheet

Panes and Layouts

Use this tmux reference while you build software engineering projects, review code, or refresh the syntax you reach for most.

Pane Bindings

KeysAction
prefix %Split left / right (vertical divider)
prefix "Split top / bottom (horizontal divider)
prefix oCycle to the next pane
prefix ;Toggle to the last active pane
prefix ←↓↑→Move focus in that direction
prefix qShow pane numbers; press one to jump
prefix xKill this pane
prefix zZoom: make this pane fill the window, toggle
prefix !Break this pane out into its own window
prefix { / prefix }Swap this pane with the previous / next
prefix Ctrl-oRotate the panes
prefix spaceCycle through the preset layouts
prefix M-1M-5Apply a specific preset layout

The % and " mnemonics confuse everyone at first. % looks like a vertical bar between two things, so it splits left/right. " looks like a stacked pair, so it splits top/bottom.

prefix z (zoom) is the single most useful pane binding: temporarily go full screen to read output or run an editor, press it again to get your layout back.

Panes From the Command Line

tmux split-window                 # split top/bottom
tmux split-window -h              # split left/right
tmux split-window -v              # split top/bottom, explicit
tmux split-window -c "#{pane_current_path}"   # inherit the cwd
tmux split-window -h -p 30        # new pane takes 30 percent
tmux split-window -h -l 40        # new pane is 40 columns
tmux split-window -d 'npm test'   # split, run a command, stay put
tmux split-window -f -h           # split the full window height, not just the pane
tmux select-pane -t 2
tmux select-pane -L               # -L -R -U -D by direction
tmux swap-pane -s 1 -t 2
tmux kill-pane -t 2
tmux kill-pane -a                 # kill every pane but this one
tmux break-pane                   # pane becomes its own window
tmux join-pane -s 3 -t 1          # pull window 3 in as a pane of window 1
tmux join-pane -h -s work:2 -t work:1
tmux resize-pane -D 10            # -U -D -L -R
tmux resize-pane -Z               # toggle zoom
tmux list-panes
tmux list-panes -a                # across every window

join-pane and break-pane are the pair to remember: they let you rearrange a layout after the fact instead of killing and recreating shells.

Resizing

KeysAction
prefix Ctrl-←↓↑→Resize by one cell
prefix M-←↓↑→Resize by five cells
prefix zZoom, which is usually what you actually wanted
Drag the dividerWith the mouse on, if mouse is enabled
# Repeatable resize bindings: hold the key after the prefix
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5

The -r flag makes a binding repeatable, so prefix H H H resizes three times without pressing the prefix again.

Layouts

LayoutArrangement
even-horizontalPanes side by side, equal width
even-verticalPanes stacked, equal height
main-horizontalOne large pane on top, the rest in a row below
main-verticalOne large pane on the left, the rest in a column right
tiledA grid
tmux select-layout tiled
tmux select-layout main-vertical
tmux select-layout even-horizontal
tmux next-layout                       # same as prefix space
tmux setw main-pane-width 100          # size of the 'main' pane
tmux setw main-pane-height 30
tmux select-layout                     # reapply the current layout

A layout can be captured as a string and restored exactly:

tmux list-windows -F "#{window_layout}"
tmux select-layout "d2b1,204x50,0,0[204x35,0,0,1,204x14,0,36,2]"

Synchronize Panes

Type once, send to every pane in the window. Useful for running the same command on several servers.

tmux setw synchronize-panes on
tmux setw synchronize-panes off
tmux setw synchronize-panes          # toggle
bind S setw synchronize-panes \; display "sync #{?pane_synchronized,on,off}"

Turn it off as soon as you are done. Forgetting it on and typing rm is a memorable mistake.