Tmux
- Description: tmux terminal multiplexer — persistent shells over SSH, sessions/windows/panes, copy mode, and configuration.
- My Notion Note ID: K2B-1-2
- Created: 2020-06-08
- Updated: 2026-05-15
- License: Reuse is very welcome. Please credit Yu Zhang and link back to the original on yuzhang.io
Table of Contents
- 1. Overview
- 2. Installation and First Run
- 3. Mental Model
- 4. Sessions
- 5. Windows
- 6. Panes
- 7. Copy Mode
- 8. Configuration
- 9. Plugins (tpm)
- 10. Sample Config
- 11. Pitfalls
- 12. References
1. Overview
Persistent shells, decoupled from terminal emulator — primary reason to use tmux.
- Close terminal / drop SSH / reboot laptop → shells keep running on server.
tmux attachrestores pane layout + scrollback exactly.
Other capabilities (same architecture):
- Windows (tabs) + panes (splits) inside one emulator window.
- Scriptable session model — save, restore, launch from config or wrapper (
tmuxinator,tmuxp). - Copy mode — scrollback as navigable buffer, vi or emacs keys.
Neighbours:
| Tool | Persistence | Splits | Scriptable layout | Notes |
|---|---|---|---|---|
screen |
Yes | Yes (horizontal + vertical, 4.1+) | Weak | Older, GPLv3-licensed, simpler keybinds. |
tmux |
Yes | Yes (full grid) | Strong | ISC-licensed, active development. |
| Terminator/iTerm | No | Yes | GUI-only | Layout dies with the terminal process. |
2. Installation and First Run
# Debian/Ubuntu
sudo apt install tmux
# Fedora/RHEL
sudo dnf install tmux
# macOS (Homebrew)
brew install tmux
# Arch Linux
sudo pacman -S tmux
Verify + start named session:
tmux -V # e.g. tmux 3.4
tmux new -s work # start a new session called "work"
Status bar: session name (left), window list (centre), host/time (right). Outside tmux → tmux ls lists running sessions.
3. Mental Model
Hierarchy, outside in:
- Server — one background process per user. First
tmuxspawns it;tmux kill-serverends it. All sessions share one server. - Session — collection of windows. Detach → still running, reattach from any terminal.
- Window — like a tab. Layout of one or more panes.
- Pane — single pseudo-terminal running a shell or program. Split horizontally or vertically.
Prefix key starts every binding. Default C-b. This note uses C-x (rebound, see §8) — substitute C-b on a stock install. Chord, not held combo: press prefix, release, press next key.
4. Sessions
| Action | Shell command | In-tmux binding |
|---|---|---|
| List sessions | tmux ls |
C-x s |
| New named session | tmux new -s <name> |
— |
| Attach to most recent | tmux a (or tmux attach) |
— |
| Attach to specific | tmux a -t <name> |
— |
| Detach (leave running) | — | C-x d |
| Rename current session | — | C-x $ |
| Switch to another session | — | C-x s then select |
| Kill one session | tmux kill-session -t <name> |
— |
| Kill server (all sessions) | tmux kill-server |
— |
- Detach = normal exit; all panes keep running.
exitin the last pane of the last window → kills session.tmux new -As work— attach toworkif it exists, else create. Common in.bashrcfor auto-attach on SSH login.
5. Windows
| Binding (after prefix) | Action |
|---|---|
c |
Create new window |
, |
Rename current window |
& |
Kill current window (asks for confirmation) |
n / p |
Next / previous window |
0–9 |
Switch to window by index |
w |
Interactive window list |
f |
Find window by text |
. |
Move window to a new index |
' |
Prompt for window index to jump to |
- Status bar marks current window
*, previously-active-. C-x l→ last-used window.- Default index starts at
0.base-index 1→ start at1, aligns with number-row layout.
6. Panes
6.1 Pane Splits
| Default binding | Action |
|---|---|
C-x % |
Split vertically (left/right) |
C-x " |
Split horizontally (top/bottom) |
Default mnemonic widely considered unmemorable → most configs rebind to C-x v / C-x h (or | / -). See §10.
6.2 Navigation and Resize
| Binding | Action |
|---|---|
C-x <arrow> |
Move focus in that direction |
C-x o |
Cycle to next pane |
C-x ; |
Toggle to last active pane |
C-x q |
Briefly show pane numbers; press number to jump |
C-x <hold><arrow> |
Resize pane (repeat while held) |
C-x M-<arrow> |
Resize in steps of 5 |
C-x z |
Zoom current pane to fill window (toggle) |
C-x ! |
Promote pane to its own window |
C-x x |
Kill current pane (asks for confirmation; exit also works, no prompt) |
C-x { / C-x } |
Swap pane with previous / next |
C-x <space> |
Cycle through layout presets |
6.3 Layout Presets
After prefix, apply a built-in layout:
| Binding | Layout |
|---|---|
C-x M-1 |
even-horizontal |
C-x M-2 |
even-vertical |
C-x M-3 |
main-horizontal |
C-x M-4 |
main-vertical |
C-x M-5 |
tiled |
C-x M-6 |
main-horizontal-mirrored (tmux 3.5+) |
C-x M-7 |
main-vertical-mirrored (tmux 3.5+) |
Non-interactive: tmux select-layout tiled.
7. Copy Mode
Turns active pane → navigable buffer over screen + scrollback.
| Binding (after prefix) | Action |
|---|---|
[ |
Enter copy mode |
] |
Paste most recent buffer |
= |
Choose buffer from list, then paste |
# |
List all paste buffers |
Navigation depends on mode-keys:
- emacs (default) —
C-Spacestart selection,M-wcopy,C-rreverse search. - vi (
setw -g mode-keys vi) —vstart selection,yyank,/and?search,n/Nrepeat.
Exit copy mode: q or Escape. System clipboard not built in — pipe buffer through external tool:
# Linux (X11): requires xclip
bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "xclip -in -selection clipboard"
# Wayland: replace xclip with wl-copy
bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "wl-copy"
# macOS
bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "pbcopy"
With set -g mouse on: hold Shift while selecting → bypasses tmux, uses terminal's native copy (targets system clipboard). Middle-click → pastes X11 primary selection.
8. Configuration
Config: ~/.tmux.conf (per-user) or /etc/tmux.conf (system-wide). Reload while running:
tmux source-file ~/.tmux.conf
Or bind a reload key (see sample) → C-x r.
Three directive families:
set -g <option> <value>— server/session options.setw -g <option> <value>— window options (setw≡set-window-option).bind <key> <command>— after-prefix;bind -n→ no prefix;bind -r→ repeat without re-pressing prefix.
8.1 Common Rebinds
# Replace the prefix
unbind C-b
set -g prefix C-x
bind C-x send-prefix # press prefix twice to send literal C-x
# Saner split bindings
unbind '"'
unbind %
bind h split-window -h # horizontal split (panes side-by-side)
bind v split-window -v # vertical split (panes stacked)
# Vim-style pane navigation without prefix
bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D
# Window switching without prefix
bind -n S-Left previous-window
bind -n S-Right next-window
# Mouse mode
set -g mouse on
# Vi keys in copy mode
setw -g mode-keys vi
# Faster repeat for resize
set -g repeat-time 600
# Reload config with prefix + r
bind r source-file ~/.tmux.conf \; display-message "tmux.conf reloaded"
bind -n≡bind -T root— root key table, prefix not required. Useful for chords likeM-Left.- Check for collisions first —
Alt-arrowis rebound by some terminal emulators.
9. Plugins (tpm)
tpm — de-facto plugin manager. Install:
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
Append to ~/.tmux.conf:
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'
run '~/.tmux/plugins/tpm/tpm' # must be last line
Inside tmux: prefix + I install, prefix + U update, prefix + alt-u remove unlisted.
Notable plugins:
- tmux-sensible — opinionated defaults (escape time, history limit, mouse-friendly).
- tmux-resurrect — saves session state to disk.
prefix + C-ssave,prefix + C-rrestore. - tmux-continuum — auto-saves resurrect state every 15 min. Auto-restore on start is opt-in:
set -g @continuum-restore 'on'. - tmux-yank — copy-mode bindings targeting system clipboard out of the box.
10. Sample Config
Minimal personal ~/.tmux.conf:
# --- prefix ------------------------------------------------------------------
unbind C-b
set -g prefix C-x
bind C-x send-prefix
# --- general -----------------------------------------------------------------
set -g mouse on
set -g history-limit 50000
set -sg escape-time 0
set -g default-terminal "screen-256color"
setw -g mode-keys vi
# --- pane splits -------------------------------------------------------------
bind h split-window -h -c "#{pane_current_path}"
bind v split-window -v -c "#{pane_current_path}"
# --- pane navigation (no prefix) --------------------------------------------
bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D
# --- window navigation (no prefix) ------------------------------------------
bind -n S-Left previous-window
bind -n S-Right next-window
# --- quick reload ------------------------------------------------------------
bind r source-file ~/.tmux.conf \; display-message "tmux.conf reloaded"
-c "#{pane_current_path}"→ new splits inherit current pane's cwd (rarely the default).history-limitdefault 2000 → bumping costs only memory.
11. Pitfalls
- ESC delay breaks Vim. tmux waits ≤500 ms after
Escapeto disambiguate meta-sequences. Fix:set -sg escape-time 0(or10). - Colours look washed out. Programs check
TERM. Broad compatibility:set -g default-terminal "screen-256color". True-colour:"tmux-256color"+terminal-overrides ",xterm-256color:RGB". - Nested tmux sessions. SSH into remote, start tmux inside outer tmux → prefix ambiguous. Press prefix twice (
C-x C-xhere) → sends through to inner. Or bind a distinct prefix on the remote. - Mouse-mode copy. With
mouse on, drag selects into tmux's paste buffer, not system clipboard. HoldShiftwhile selecting → bypass tmux, use terminal's native selection. - Status bar truncation in long sessions. Long pane titles or status segments shrink centre window list. Budget explicitly:
set -g status-left-length 40,status-right-length 60. exitvskill-pane. Closing the last pane of the last window kills the session. Avoid accidentalexit→ detach first (C-x d).- Reload before debugging. Edits to
~/.tmux.confdon't apply untilsource-file(or server restart). Many "binding doesn't work" reports trace to this.
12. References
man tmux— authoritative reference.- tmux GitHub wiki — getting-started guide, FAQ, and recipes.
- Brian P. Hogan, tmux 2: Productive Mouse-Free Development — Pragmatic Bookshelf.
- The Tao of Tmux — free online, covers internals and idioms.
- Mark Hamvocke, A Guide to Customizing Your Tmux.conf — practical config walkthrough.
- tmux-plugins organisation on GitHub — tpm and the canonical plugins.