Tmux Cheat Sheet
Terminal multiplexer commands for managing sessions, windows, and panes that persist across SSH disconnects.
Session Management
Create and reattach to persistent sessions.
tmux new -s work # Start a new named sessiontmux ls # List sessionstmux attach -t work # Reattach to a sessiontmux kill-session -t work # Kill a specific sessiontmux detach # Detach (or press prefix + d)
Key Bindings (prefix = Ctrl-b)
Default prefix key followed by these commands.
- c- Create a new window
- n / p- Move to next / previous window
- 0-9- Jump directly to window number
- %- Split pane vertically (side by side)
- "- Split pane horizontally (stacked)
- arrow keys / o- Move between panes
- z- Zoom/unzoom the current pane to full screen
- d- Detach from the session
~/.tmux.conf Basics
Common customizations.
# Remap prefix to Ctrl-aset -g prefix C-aunbind C-bbind C-a send-prefix# Enable mouse supportset -g mouse on# Start window numbering at 1set -g base-index 1
Scripting Sessions with tmux(1)
Drive tmux non-interactively from shell scripts to bootstrap a whole dev layout in one command.
#!/usr/bin/env bash# Build a 3-pane dev layout and attachSESSION="dev"tmux new-session -d -s "$SESSION" -n editortmux send-keys -t "$SESSION:editor" 'nvim .' C-mtmux new-window -t "$SESSION" -n servertmux send-keys -t "$SESSION:server" 'npm run dev' C-mtmux split-window -h -t "$SESSION:server"tmux send-keys -t "$SESSION:server.1" 'npm run test:watch' C-mtmux select-layout -t "$SESSION:server" tiledtmux attach -t "$SESSION"
Pane & Window Manipulation
Resize, swap, and synchronize panes without leaving the keyboard.
# prefix + { / } swap current pane with previous/next# prefix + Ctrl-arrow resize pane in that direction# prefix + ! break current pane out into its own window# prefix + :join-pane -s 2 join window 2 into current window as a pane# prefix + q briefly show pane numbers, press number to jump# Toggle synchronized input across all panes (type once, run everywhere)tmux set-window-option synchronize-panes ontmux set-window-option synchronize-panes off
Dynamic Status Line
Embed shell command output and conditional styling directly in the status bar.
# ~/.tmux.confset -g status-interval 5set -g status-right '#[fg=cyan]#(git -C #{pane_current_path} branch --show-current) #[fg=yellow]%H:%M'set -g status-left '#[fg=green]#S #[fg=white]| #{pane_current_command}'# Highlight the active pane borderset -g pane-active-border-style fg=greenset -g pane-border-style fg=colour238
Advanced Concepts
Terminology and mechanisms that matter once you're scripting or nesting tmux.
- Client vs. server model- A single tmux server process holds all sessions; clients are just terminals attached to it, so killing a terminal never kills the server
- hooks- tmux fires internal events (session-created, pane-died, client-attached) that you can bind to run commands, e.g. `set-hook -g pane-died 'display-message "pane exited"'`
- buffers- tmux's internal copy-paste stack (`prefix + [` to copy, `prefix + ]` to paste); `tmux show-buffer` and `tmux save-buffer` script access to it
- nested tmux (send-prefix -a)- Bind `C-a a` to `send-prefix` so an outer session can forward a keystroke to an inner tmux running over SSH
- control mode (-CC)- `tmux -CC` emits a line-based protocol consumed by GUI front-ends like iTerm2's native tmux integration
- format strings- `#{...}` variables (e.g. `#{pane_current_path}`, `#{session_windows}`) usable in status-line, window names, and popups
Popups & Automatic Layout Restore
Modern tmux (3.2+) popups and resurrect-style persistence for surviving reboots.
# Floating popup running a scratch command (tmux >= 3.2)tmux display-popup -E -w 80% -h 60% 'lazygit'# Bind a quick popup shellbind-key g display-popup -E -d '#{pane_current_path}' 'bash'# Persist and restore sessions across reboots (tmux-resurrect / tmux-continuum plugins)set -g @plugin 'tmux-plugins/tmux-resurrect'set -g @plugin 'tmux-plugins/tmux-continuum'set -g @continuum-restore 'on'
Start long-running remote work inside a named tmux session before you SSH in for the day — if your connection drops, the session (and every process in it) keeps running, and 'tmux attach' picks up exactly where you left off.