tmux Cheat Sheet

Most used
tmux new -s work          # start a named session
Ctrl+b d                  # detach (session keeps running)
tmux ls                   # list sessions
tmux attach -t work       # reattach
Ctrl+b %   /   Ctrl+b "   # split left/right  /  top/bottom
Ctrl+b [                  # scroll / copy mode (q to exit)

tmux keeps terminal sessions running on a machine after you disconnect, and splits one terminal into windows and panes. Every key binding starts with the prefix, Ctrl+b by default: press and release it, then press the command key. Below, Prefix means Ctrl+b. Install with sudo apt install tmux, sudo dnf install tmux, sudo pacman -S tmux or sudo zypper install tmux; check your version with tmux -V.

Sessions

CommandWhat it does
tmuxStart a new unnamed session
tmux new -s nameStart a named session
tmux new -A -s nameAttach to name if it exists, otherwise create it
tmux new -d -s job 'long-command'Start a detached session running a command
tmux lsList sessions
tmux attach / tmux aAttach to the most recent session
tmux attach -t nameAttach to a named session
tmux attach -d -t nameAttach and detach other clients (fixes a too-small window)
tmux kill-session -t nameEnd a session and everything in it
tmux kill-serverEnd all sessions
tmux rename-session -t old newRename a session
Prefix dDetach
Prefix sInteractive session list (switch with Enter)
Prefix $Rename the current session
Prefix ( / Prefix )Previous / next session

Windows (tabs)

CommandWhat it does
Prefix cCreate a window
Prefix ,Rename the window
Prefix n / Prefix pNext / previous window
Prefix 0…9Go to window by number
Prefix lLast (previously used) window
Prefix wTree view of all sessions and windows
Prefix fFind a window by text
Prefix &Kill the window (asks for confirmation)
Prefix .Move the window to another index
tmux swap-window -s 2 -t 1Swap window 2 and window 1

Panes (splits)

CommandWhat it does
Prefix %Split left/right
Prefix "Split top/bottom
Prefix + arrow keyMove to the pane in that direction
Prefix oCycle through panes
Prefix ;Last active pane
Prefix qShow pane numbers (press a number to jump)
Prefix zZoom the pane to full window and back
Prefix xKill the pane (or just type exit)
Prefix !Break the pane out into its own window
Prefix { / Prefix }Swap the pane with the previous / next
Prefix SpaceCycle through preset layouts
Prefix Alt+1…Alt+5Pick a layout (even-horizontal, even-vertical, main-horizontal, main-vertical, tiled)
Prefix Ctrl+arrowResize by 1 cell (Prefix Alt+arrow by 5)
tmux resize-pane -D 10Resize down by 10 lines (-U, -L, -R)
:setw synchronize-panes onType into all panes of the window at once
tmux join-pane -s 2 -t 1Move window 2's pane into window 1

Copy mode and scrollback

Default keys in copy mode follow Emacs unless your EDITOR/VISUAL contains vi, in which case tmux uses vi keys. Force it with setw -g mode-keys vi.

CommandWhat it does
Prefix [Enter copy mode (scroll with arrows, PgUp/PgDn)
Prefix PgUpEnter copy mode and scroll up one page
qLeave copy mode
Space / Entervi keys: start selection / copy and exit
v then ySame, after binding them in the config below
Ctrl+Space / Alt+wEmacs keys: start selection / copy
/ / ?Search down / up (vi keys); n next match
Prefix ]Paste the most recent buffer
Prefix =Choose a buffer to paste from a list
tmux capture-pane -pS -3000 > out.txtSave the last 3000 lines of a pane to a file

Command prompt and misc

CommandWhat it does
Prefix :Open the tmux command prompt
Prefix ?List all key bindings
Prefix tShow a big clock
Prefix rRedraw the client
Prefix Ctrl+bSend a literal Ctrl+b to the program (e.g. nested tmux)
tmux source-file ~/.tmux.confReload the configuration
tmux show -g / tmux show -gwShow global session / window options
tmux send-keys -t job 'ls' EnterType into a session from a script
tmux list-keysAll bindings, as config lines

Common recipes

A practical ~/.tmux.conf (tmux 3.1+ also reads ~/.config/tmux/tmux.conf):

# mouse: click panes, drag borders, scroll with the wheel
set -g mouse on
# more scrollback
set -g history-limit 50000
# windows and panes numbered from 1
set -g base-index 1
setw -g pane-base-index 1
set -g renumber-windows on
# no delay after Esc (important in Vim)
set -sg escape-time 10
# true colour in modern terminals
set -as terminal-features ',*:RGB'
# vi keys in copy mode, v to select, y to copy
setw -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
# split in the current directory with easier keys
bind | split-window -h -c '#{pane_current_path}'
bind - split-window -v -c '#{pane_current_path}'
# reload config
bind R source-file ~/.tmux.conf \; display 'reloaded'

Use Ctrl+a as the prefix (screen-style):

unbind C-b
set -g prefix C-a
bind C-a send-prefix

Always land in the same session when you SSH in (pairs with the SSH cheat sheet):

ssh -t server 'tmux new -A -s main'

Run a long upgrade safely on a remote server, then check on it later:

tmux new -s upgrade
sudo apt full-upgrade      # or dnf / pacman / zypper
# Prefix d to detach, log out, come back later:
tmux attach -t upgrade

Script a development layout:

tmux new -d -s dev -c ~/project
tmux split-window -h -t dev -c ~/project
tmux send-keys -t dev:1.1 'vim .' Enter
tmux send-keys -t dev:1.2 'npm run dev' Enter
tmux attach -t dev

(The target dev:1.2 means session dev, window 1, pane 2, with the base-index 1 settings above; use dev:0.0 and dev:0.1 with defaults.)

Copy to the system clipboard. tmux 3.2+ supports OSC 52, which works in most modern terminals even over SSH:

set -g set-clipboard on
# or pipe to a clipboard tool on Wayland:
bind -T copy-mode-vi y send -X copy-pipe-and-cancel 'wl-copy'

Gotchas

  • Prefix, then release. Press Ctrl+b, let go, then press the key. Holding Ctrl sends a different binding (e.g. Prefix Ctrl+arrow resizes instead of moving).
  • Config changes don't apply to running sessions until you source-file the config; some options (like default-terminal) only apply to new sessions or after tmux kill-server.
  • Laggy Esc in Vim. Before tmux 3.5 the default escape-time was 500 ms, which makes Vim feel slow inside tmux. Set it to 10 or lower explicitly so the behaviour is the same on every version.
  • Colours look wrong. Set set -g default-terminal 'tmux-256color' (recent releases default to it when the terminfo entry exists) and add the RGB terminal feature for true colour. Very old remote hosts may lack the tmux-256color terminfo; use screen-256color there.
  • Mouse mode changes selection. With mouse on, dragging selects into tmux's buffer, not the terminal's. Hold Shift while selecting to use the terminal's native selection.
  • "sessions should be nested with care". You ran tmux inside tmux. Detach, or press the prefix twice to talk to the inner session.
  • Sessions die on reboot. tmux runs in memory. On systemd distros, sessions started over SSH can also be killed at logout if KillUserProcesses=yes is set in logind.conf (not the default on most distros); loginctl enable-linger avoids it.
  • Old option names. Options like mode-mouse, utf8 and vi-copy tables were removed in tmux 2.x; copied configs using them fail with "unknown option". Use the forms on this page.

Reference: tmux(1) and the tmux wiki. Editing inside tmux: Vim cheat sheet; terminal basics: getting comfortable in the terminal.

Frequently asked questions

How do I detach from tmux and reattach later?

Press Ctrl+b then d to detach. Reattach with tmux attach, or tmux attach -t name for a specific session.

How do I scroll up in tmux?

Press Ctrl+b then [ to enter copy mode, scroll with the arrow keys or Page Up, and press q to leave. Add set -g mouse on to scroll with the mouse wheel.

How do I split the screen in tmux?

Ctrl+b % splits left/right and Ctrl+b " splits top/bottom. Move between panes with Ctrl+b and an arrow key.

Does a tmux session survive if my SSH connection drops?

Yes. The tmux server keeps running on the remote machine; SSH in again and run tmux attach. It does not survive a reboot of that machine.

How do I reload my tmux config?

Run tmux source-file ~/.tmux.conf, or press Ctrl+b : and type source-file ~/.tmux.conf.

Spotted a mistake or a command that no longer works? Send a correction — pages are re-checked when reports come in.