tmux Cheat Sheet
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
| Command | What it does |
|---|---|
tmux | Start a new unnamed session |
tmux new -s name | Start a named session |
tmux new -A -s name | Attach to name if it exists, otherwise create it |
tmux new -d -s job 'long-command' | Start a detached session running a command |
tmux ls | List sessions |
tmux attach / tmux a | Attach to the most recent session |
tmux attach -t name | Attach to a named session |
tmux attach -d -t name | Attach and detach other clients (fixes a too-small window) |
tmux kill-session -t name | End a session and everything in it |
tmux kill-server | End all sessions |
tmux rename-session -t old new | Rename a session |
Prefix d | Detach |
Prefix s | Interactive session list (switch with Enter) |
Prefix $ | Rename the current session |
Prefix ( / Prefix ) | Previous / next session |
Windows (tabs)
| Command | What it does |
|---|---|
Prefix c | Create a window |
Prefix , | Rename the window |
Prefix n / Prefix p | Next / previous window |
Prefix 0…9 | Go to window by number |
Prefix l | Last (previously used) window |
Prefix w | Tree view of all sessions and windows |
Prefix f | Find a window by text |
Prefix & | Kill the window (asks for confirmation) |
Prefix . | Move the window to another index |
tmux swap-window -s 2 -t 1 | Swap window 2 and window 1 |
Panes (splits)
| Command | What it does |
|---|---|
Prefix % | Split left/right |
Prefix " | Split top/bottom |
Prefix + arrow key | Move to the pane in that direction |
Prefix o | Cycle through panes |
Prefix ; | Last active pane |
Prefix q | Show pane numbers (press a number to jump) |
Prefix z | Zoom the pane to full window and back |
Prefix x | Kill 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 Space | Cycle through preset layouts |
Prefix Alt+1…Alt+5 | Pick a layout (even-horizontal, even-vertical, main-horizontal, main-vertical, tiled) |
Prefix Ctrl+arrow | Resize by 1 cell (Prefix Alt+arrow by 5) |
tmux resize-pane -D 10 | Resize down by 10 lines (-U, -L, -R) |
:setw synchronize-panes on | Type into all panes of the window at once |
tmux join-pane -s 2 -t 1 | Move 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.
| Command | What it does |
|---|---|
Prefix [ | Enter copy mode (scroll with arrows, PgUp/PgDn) |
Prefix PgUp | Enter copy mode and scroll up one page |
q | Leave copy mode |
Space / Enter | vi keys: start selection / copy and exit |
v then y | Same, after binding them in the config below |
Ctrl+Space / Alt+w | Emacs 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.txt | Save the last 3000 lines of a pane to a file |
Command prompt and misc
| Command | What it does |
|---|---|
Prefix : | Open the tmux command prompt |
Prefix ? | List all key bindings |
Prefix t | Show a big clock |
Prefix r | Redraw the client |
Prefix Ctrl+b | Send a literal Ctrl+b to the program (e.g. nested tmux) |
tmux source-file ~/.tmux.conf | Reload the configuration |
tmux show -g / tmux show -gw | Show global session / window options |
tmux send-keys -t job 'ls' Enter | Type into a session from a script |
tmux list-keys | All 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+arrowresizes instead of moving). - Config changes don't apply to running sessions until you
source-filethe config; some options (likedefault-terminal) only apply to new sessions or aftertmux kill-server. - Laggy Esc in Vim. Before tmux 3.5 the default
escape-timewas 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 theRGBterminal feature for true colour. Very old remote hosts may lack the tmux-256color terminfo; usescreen-256colorthere. - 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=yesis set inlogind.conf(not the default on most distros);loginctl enable-lingeravoids it. - Old option names. Options like
mode-mouse,utf8andvi-copytables 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.