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.

CommandEffect
tmux new -s workNew session named work.
tmux lsList sessions.
tmux attach -t workAttach (tmux attach alone picks the most recent session).
tmux attach -d -t workAttach and detach other clients (use after a dropped SSH link).
tmux kill-session -t workKill a session.
prefix dDetach; the session keeps running.
prefix $ / prefix sRename / pick a session.
prefix ( / prefix )Previous / next session.

Windows and panes

Use one window per task and prefix z to focus a pane.

KeyEffect
prefix c / , / &New / rename / kill window.
prefix n p l 0-9Next / previous / last / by number.
prefix wInteractive window and session tree.
prefix % / "Split into left and right / top and bottom.
prefix arrow, prefix oMove to a pane / cycle panes.
prefix zZoom the pane (press again to restore).
prefix Ctrl-arrow / Alt-arrowResize by 1 / 5 cells.
prefix { } / SpaceSwap panes / cycle layouts.
prefix x / !Kill pane / break it into its own window.
prefix qShow 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.

Actionemacs keys (default)vi keys (mode-keys vi)
Start selectionCtrl-SpaceSpace
CopyM-w or Ctrl-wEnter
SearchCtrl-s / Ctrl-r, then n N/ ?, then n N
Exitq or Escq

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.

GotchaFix
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.