Overview
tmux keeps terminal sessions alive across SSH drops and splits one terminal into windows and panes. Key bindings below use the default prefix Ctrl-b: press it, release, then press the key. Verified on tmux 3.4. Vim-style editing is in vim-commands.
Sessions
Name every session so tmux ls stays readable.
| Command | Effect |
|---|---|
tmux new -s work | New session named work. |
tmux ls | List sessions. |
tmux attach -t work | Attach (tmux attach alone picks the most recent session). |
tmux attach -d -t work | Attach and detach other clients (use after a dropped SSH link). |
tmux kill-session -t work | Kill a session. |
prefix d | Detach; the session keeps running. |
prefix $ / prefix s | Rename / pick a session. |
prefix ( / prefix ) | Previous / next session. |
Windows and panes
Use one window per task and prefix z to focus a pane.
| Key | Effect |
|---|---|
prefix c / , / & | New / rename / kill window. |
prefix n p l 0-9 | Next / previous / last / by number. |
prefix w | Interactive window and session tree. |
prefix % / " | Split into left and right / top and bottom. |
prefix arrow, prefix o | Move to a pane / cycle panes. |
prefix z | Zoom the pane (press again to restore). |
prefix Ctrl-arrow / Alt-arrow | Resize by 1 / 5 cells. |
prefix { } / Space | Swap panes / cycle layouts. |
prefix x / ! | Kill pane / break it into its own window. |
prefix q | Show pane numbers; press one to jump to that pane. |
Copy mode
prefix [ enters copy mode, prefix ] pastes the tmux buffer, prefix = picks an older buffer. Keys depend on mode-keys; the default is emacs unless $VISUAL or $EDITOR contains vi.
| Action | emacs keys (default) | vi keys (mode-keys vi) |
|---|---|---|
| Start selection | Ctrl-Space | Space |
| Copy | M-w or Ctrl-w | Enter |
| Search | Ctrl-s / Ctrl-r, then n N | / ?, then n N |
| Exit | q or Esc | q |
Config
Put this in ~/.tmux.conf, reload with prefix : then source-file ~/.tmux.conf, or use the r binding.
unbind C-b
set -g prefix C-a
bind C-a send-prefix
set -g mode-keys vi
bind -T copy-mode-vi v send -X begin-selection
bind -T copy-mode-vi y send -X copy-selection-and-cancel
set -g base-index 1
setw -g pane-base-index 1
set -g history-limit 50000 # default is 2000
set -g mouse on
set -g set-clipboard on # copy to the system clipboard via OSC 52
bind r source-file ~/.tmux.conf \; display "Reloaded"Keep the file in dotfiles.
Gotchas
Avoid these; each loses a session or copies to the wrong place.
| Gotcha | Fix |
|---|---|
Default copy mode is emacs-style (unless $VISUAL or $EDITOR contains vi): Space pages down and / does nothing. | set -g mode-keys vi. |
| A copy lands in the tmux buffer, not the system clipboard. | set -g set-clipboard on, or bind y to copy-pipe with xclip or pbcopy. |
prefix d detaches; it does not stop the session. | tmux kill-session, or exit in every pane. |
| A job started outside tmux dies with its terminal. | Start servers and builds inside a named session. |
| A zoomed pane looks like the only pane. | prefix z restores the layout. |