Skip to content

Build master @ bc50cd5bunreleased — 31 commits past v1.282.0Last reviewed Last changed Grade fresh (aging >90d, stale >180d)Source / History

tmux Cheatsheet ​

Prefix key: Ctrl-b (referred to as C-b below)

Starting / Attaching ​

bash
tmux                          # New unnamed session
tmux new -s farm              # New session named "farm"
tmux ls                       # List sessions
tmux a                        # Attach to last session
tmux a -t farm                # Attach to session named "farm"
tmux kill-session -t farm     # Kill session
tmux kill-server              # Kill everything

Sessions ​

KeysAction
C-b dDetach from session
C-b $Rename session
C-b sList/switch sessions
C-b (Previous session
C-b )Next session

Windows (tabs) ​

KeysAction
C-b cNew window
C-b ,Rename window
C-b &Kill window
C-b wList windows (interactive picker)
C-b nNext window
C-b pPrevious window
C-b 0-9Jump to window by number
C-b lLast active window

Panes (splits) ​

KeysAction
C-b %Split vertical (left/right)
C-b "Split horizontal (top/bottom)
C-b xKill pane
C-b oCycle to next pane
C-b ;Toggle to last active pane
C-b qShow pane numbers, then press number to jump
C-b zZoom/unzoom pane (fullscreen toggle)
C-b {Move pane left
C-b }Move pane right
C-b SpaceCycle pane layouts
C-b !Convert pane to its own window

Resizing panes ​

KeysAction
C-b C-arrowResize by 1 cell
C-b M-arrowResize by 5 cells

Copy / Scroll Mode ​

KeysAction
C-b [Enter copy/scroll mode
qExit copy mode
SpaceStart selection (in copy mode)
EnterCopy selection and exit
C-b ]Paste buffer
/Search forward (in copy mode)
?Search backward (in copy mode)
gJump to top
GJump to bottom

Arrow keys and Page Up/Down work in copy mode.

The in-copy-mode keys above (Space, Enter, /, ?, g, G) are the vi copy-mode bindings. tmux defaults to mode-keys emacs (vi only when $EDITOR/$VISUAL names vi), where the equivalents are C-Space to select, M-w to copy, C-s / C-r to search and M-< / M-> for top / bottom — or add set -g mode-keys vi (see Useful Options).

Running Long Processes on Farm ​

Fire and forget ​

bash
# Start session, kick off process, detach
tmux new -s deploy -d 'cd ~/projects/bodmail && npm run build'

# Check on it later
tmux a -t deploy

Multi-window workflow ​

bash
# Create a session with named windows
tmux new -s farm -n logs -d
tmux new-window -t farm -n build
tmux new-window -t farm -n monitor

# Send commands to specific windows
tmux send-keys -t farm:logs 'tail -f /var/log/app.log' Enter
tmux send-keys -t farm:build 'npm run build' Enter
tmux send-keys -t farm:monitor 'htop' Enter

# Attach when ready
tmux a -t farm

Run command in existing session ​

bash
tmux send-keys -t farm:0 'npm test' Enter

Wait for a command to finish ​

bash
# Run in a pane and get notified
tmux set -t farm monitor-activity on
# Now switch to another window — tmux highlights the window when activity occurs

Capture output from a pane ​

bash
tmux capture-pane -t farm:0 -p > output.txt         # Current visible
tmux capture-pane -t farm:0 -p -S -1000 > output.txt # Last 1000 lines

Useful Options ​

bash
# Mouse support (scrolling, clicking panes, resizing)
tmux set -g mouse on

# Increase scrollback buffer
tmux set -g history-limit 50000

# Start window numbering at 1
tmux set -g base-index 1
tmux set -g pane-base-index 1

# vi keys in copy mode (Space / Enter / g / G as listed above)
tmux set -g mode-keys vi

Put these in ~/.tmux.conf to make them permanent.

Quick Reference: Common Combos ​

C-b d           → detach (go do other stuff, come back later)
C-b c           → new window
C-b %           → split side by side
C-b "           → split top/bottom
C-b z           → zoom a pane to fullscreen (again to unzoom)
C-b [           → scroll up through output
C-b w           → visual window/session picker
C-b s           → session picker