Overview

tmux keeps terminal sessions alive across SSH drops, lets you split the screen into panes, and enables copying output without a mouse. This card uses the default prefix Ctrl-b. For vim-style editing in the terminal, see vim-commands.

All key bindings below assume the default prefix. After pressing Ctrl-b, release both keys, then press the next key.

Sessions

Sessions are the outermost container; detach and reattach freely.

CommandWhat it does
tmuxStart a new session.
tmux new -s workNew session named work.
tmux lsList sessions.
tmux attach -t workAttach to session work.
tmux attachAttach to the most recent session.
tmux kill-session -t workKill session work.
Ctrl-b dDetach from current session (session stays alive).
Ctrl-b $Rename current session.
Ctrl-b sInteractive session switcher.
Ctrl-b ( / Ctrl-b )Switch to previous / next session.

Name every session. tmux ls with unnamed sessions quickly becomes 0, 1, 2 with no hint of contents.

Windows

Windows are tabs within a session.

CommandWhat it does
Ctrl-b cCreate a new window.
Ctrl-b ,Rename current window.
Ctrl-b wInteractive window list.
Ctrl-b n / Ctrl-b pNext / previous window.
Ctrl-b 0-9Switch to window by number.
Ctrl-b &Kill current window (prompts).
Ctrl-b lSwitch to last (previously active) window.

Keep one window per logical task: editor, server, logs. Use the window name as a status indicator.

Panes

Panes split a window into multiple terminals.

CommandWhat it does
Ctrl-b %Split horizontally (left and right).
Ctrl-b "Split vertically (top and bottom).
Ctrl-b arrowMove focus to the pane in that direction.
Ctrl-b oCycle focus through panes.
Ctrl-b zToggle zoom on current pane (fullscreen toggle).
Ctrl-b { / Ctrl-b }Swap pane with previous / next.
Ctrl-b Ctrl-arrowResize pane in one-cell steps.
Ctrl-b xKill current pane (prompts).
Ctrl-b qShow pane numbers; press the number to jump.
Ctrl-b !Break pane out into its own window.

Ctrl-b z is the fastest way to read a full log without closing the pane layout.

Copy mode

Copy mode scrolls and copies terminal output without a mouse.

CommandWhat it does
Ctrl-b [Enter copy mode.
q or EscExit copy mode.
SpaceStart selection (default bindings).
EnterCopy selection to tmux buffer.
Ctrl-b ]Paste tmux buffer.
Ctrl-b =Choose a buffer from history to paste.
/patternSearch forward in copy mode.
?patternSearch backward.
n / NNext / previous match.

With set-window-option -g mode-keys vi in .tmux.conf, copy mode uses vim keybindings: v to select, y to copy.

Config patterns

Store config in ~/.tmux.conf; reload without restarting with Ctrl-b :source ~/.tmux.conf.

# Remap prefix to Ctrl-a (screen-style)
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix
 
# vi keys in copy mode
set-window-option -g mode-keys vi
 
# Start windows and panes at 1
set -g base-index 1
set -g pane-base-index 1
 
# More history
set -g history-limit 50000
 
# Mouse support (scroll and click to focus)
set -g mouse on
 
# Status bar
set -g status-left "[#S] "
set -g status-right "%H:%M %d-%b"
 
# Reload config
bind r source-file ~/.tmux.conf \; display "Config reloaded"

Keep the config in dotfiles so it follows you to every machine.

Common gotchas

  • SSH sessions drop and leave tmux attached in a “lost” state. Run tmux attach -d to detach it from the dead session before attaching again.
  • Copy mode copies to the tmux buffer, not the system clipboard. Install xclip (Linux) or use reattach-to-user-namespace (macOS) and bind y to pipe to the system clipboard.
  • Ctrl-b % and Ctrl-b " split in opposite orientations from what the characters suggest. Remember: % horizontal bar (splits left/right), " a pair of lines (splits top/bottom).
  • Zoomed panes (Ctrl-b z) look fullscreen but the layout is preserved. Press Ctrl-b z again to restore the split.
  • Long-running processes started outside tmux die when the terminal closes. Always start long processes (servers, builds) inside a named tmux session.
  • Ctrl-b d detaches; it does not kill the session. Use kill-session or exit inside the session to actually end it.