The one thing to understand first
Every tmux command starts with the prefix key — Ctrl+b by default. You press the prefix, release it, then press the command key. It’s a two-step chord, not a simultaneous press.
Most people remap the prefix to Ctrl+a (easier to reach). The .tmux.conf section below shows how.
Quick reference tables
Sessions
| Command | What it does |
|---|---|
tmux | Start a new unnamed session |
tmux new -s work | Start a new session named work |
tmux ls | List all sessions |
tmux attach | Attach to the most recent session |
tmux attach -t work | Attach to session named work |
tmux kill-session -t work | Kill session named work |
tmux kill-server | Kill all sessions and the tmux server |
Prefix d | Detach from current session (session keeps running) |
Prefix $ | Rename current session |
Prefix s | Interactive session switcher |
Prefix ( | Switch to previous session |
Prefix ) | Switch to next session |
Windows (tabs inside a session)
| Command | What it does |
|---|---|
Prefix c | Create a new window |
Prefix , | Rename current window |
Prefix & | Close current window (with confirmation) |
Prefix n | Next window |
Prefix p | Previous window |
Prefix 0–9 | Switch to window by number |
Prefix l | Switch to last (previously used) window |
Prefix w | Interactive window list |
Prefix . | Move window (prompts for index number) |
Prefix f | Find window by name |
Panes (splits inside a window)
| Command | What it does |
|---|---|
Prefix % | Split pane vertically (left/right) |
Prefix " | Split pane horizontally (top/bottom) |
Prefix ←↑↓→ | Move to pane in that direction |
Prefix o | Cycle through panes |
Prefix q | Show pane numbers (press number to jump) |
Prefix x | Close current pane (with confirmation) |
Prefix z | Toggle pane zoom (fullscreen) |
Prefix ! | Break pane out into its own window |
Prefix { | Swap pane with the previous one |
Prefix } | Swap pane with the next one |
Prefix Ctrl+←↑↓→ | Resize pane (hold Ctrl, tap arrow) |
Prefix Alt+←↑↓→ | Resize pane in larger steps |
Prefix Space | Cycle through built-in pane layouts |
Copy mode
| Command | What it does |
|---|---|
Prefix [ | Enter copy mode |
q | Exit copy mode |
↑↓ or j k | Scroll (use vi keys after setting mode-keys vi) |
Ctrl+b / Ctrl+f | Page up / page down |
g / G | Go to top / bottom of buffer |
/pattern | Search forward |
?pattern | Search backward |
n / N | Next / previous search match |
Space | Start selection (vi mode) |
Enter | Copy selection and exit copy mode |
Prefix ] | Paste copied text |
Miscellaneous
| Command | What it does |
|---|---|
Prefix : | Open tmux command prompt |
Prefix ? | Show all key bindings |
Prefix t | Show clock in current pane |
Prefix ~ | Show tmux messages |
Prefix i | Show current window info |
tmux source ~/.tmux.conf | Reload config without restarting |
Prefix r | Reload config (if bound in .tmux.conf) |
Detailed sections
How tmux works — the mental model
tmux has three levels of hierarchy:
Server
└── Session (named, persists after detach)
└── Window (like browser tabs)
└── Pane (splits within a window)
You can have multiple sessions, each with multiple windows, each with multiple panes. When you detach (Prefix d), the session keeps running on the server — your SSH connection can drop and everything inside tmux survives.
The Scenario: You’re SSH’d into a remote server running a long build. Your internet cuts out. Without tmux, the build dies. With tmux, you re-attach when you’re back and the build is still running. This alone is worth learning tmux.
Practical workflow — named sessions
Start your day by creating named sessions for each context:
# Create sessions for each project/context
tmux new -s infra
tmux new -s dev
tmux new -s logs
# Later, list them
tmux ls
# infra: 1 windows (created Fri Mar 28 09:00:01 2026)
# dev: 3 windows (created Fri Mar 28 09:01:44 2026)
# logs: 1 windows (created Fri Mar 28 09:02:10 2026)
# Jump to a specific session
tmux attach -t dev
Inside a session, organize windows by task. Prefix c for a new window, Prefix , to rename it.
# Inside tmux — rename the current window to "api"
Prefix ,
# type "api", press Enter
The Scenario: You’re juggling three things: an API server, a database shell, and a log tail. One tmux session, three windows named
api,db,logs. Switch between them withPrefix 1,Prefix 2,Prefix 3. No more terminal window hunting.
Copy mode and the clipboard
Copy mode uses vi or emacs keys depending on your config. Vi keys are more useful for developers already in the Vim world.
First, set vi keys in .tmux.conf:
setw -g mode-keys vi
Then the copy flow in vi mode:
Prefix [ → enter copy mode
/search-term → search for text
Space → start selection
Move cursor → extend selection
Enter → copy and exit
Prefix ] → paste
To integrate with the system clipboard on Linux (requires xclip):
# In .tmux.conf
bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "xclip -in -selection clipboard"
On macOS (uses pbcopy):
# In .tmux.conf
bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "pbcopy"
Now pressing y in copy mode copies to the system clipboard instead of just the tmux buffer.
A production-ready .tmux.conf
This config remaps the prefix, enables mouse support, sets vi keys, improves the status bar, and adds useful shortcuts. Save it to ~/.tmux.conf.
# ── Prefix ──────────────────────────────────────────────────
# Remap prefix from Ctrl+b to Ctrl+a (easier to reach)
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix
# ── General ─────────────────────────────────────────────────
set -g default-terminal "screen-256color" # 256-color support
set -g history-limit 50000 # scroll back 50k lines
set -g display-time 4000 # message display duration (ms)
set -g status-interval 5 # refresh status bar every 5s
set -g focus-events on # pass focus events to apps
# Start windows and panes at index 1 (not 0 — easier to reach on keyboard)
set -g base-index 1
setw -g pane-base-index 1
set -g renumber-windows on # re-number windows when one closes
# ── Mouse ───────────────────────────────────────────────────
set -g mouse on # click to select panes, scroll, resize
# ── Vi keys in copy mode ────────────────────────────────────
setw -g mode-keys vi
bind -T copy-mode-vi v send-keys -X begin-selection
bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "xclip -in -selection clipboard"
# ── Splits ──────────────────────────────────────────────────
# More intuitive split keys: | for vertical, - for horizontal
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
unbind '"'
unbind %
# New windows and panes open in the current directory
bind c new-window -c "#{pane_current_path}"
# ── Pane navigation (vim-style) ─────────────────────────────
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
# ── Reload config ───────────────────────────────────────────
bind r source-file ~/.tmux.conf \; display-message "Config reloaded"
# ── Status bar ──────────────────────────────────────────────
set -g status-position bottom
set -g status-bg colour234
set -g status-fg colour137
set -g status-left '#[fg=colour233,bg=colour241,bold] #S '
set -g status-right '#[fg=colour233,bg=colour241] %H:%M #[fg=colour233,bg=colour245,bold] #h '
set -g status-right-length 50
set -g status-left-length 20
setw -g window-status-current-format '#[fg=colour81,bold] #I:#W '
setw -g window-status-format '#[fg=colour138] #I:#W '
After saving, reload with:
tmux source ~/.tmux.conf
# or inside tmux: Prefix r (once the reload bind is active)
tmux Plugin Manager (TPM)
TPM lets you install community plugins with a few lines of config. Install it first:
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
Add this to the bottom of .tmux.conf:
# ── Plugins (TPM) ───────────────────────────────────────────
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible' # sane defaults
set -g @plugin 'tmux-plugins/tmux-resurrect' # save/restore sessions
set -g @plugin 'tmux-plugins/tmux-continuum' # auto-save sessions every 15 min
# tmux-continuum: auto-restore on server start
set -g @continuum-restore 'on'
# Initialize TPM (keep this at the very bottom)
run '~/.tmux/plugins/tpm/tpm'
Reload the config, then press Prefix I (capital i) to install the plugins.
Key plugin shortcuts after install:
| Command | What it does |
|---|---|
Prefix Ctrl+s | Save session (tmux-resurrect) |
Prefix Ctrl+r | Restore saved session (tmux-resurrect) |
Prefix I | Install new plugins (TPM) |
Prefix U | Update plugins (TPM) |
Prefix Alt+u | Remove unlisted plugins (TPM) |
The Scenario: Your laptop died mid-sprint. tmux-resurrect saved the session 15 minutes ago. You start fresh, press
Prefix Ctrl+r, and your six panes with running processes come back exactly as they were. Not perfect, but close enough to matter.
tmux vs screen
Both are terminal multiplexers. Most developers should use tmux in 2026.
| Feature | tmux | screen |
|---|---|---|
| Active development | Yes | Minimal |
| Config file | ~/.tmux.conf | ~/.screenrc |
| Window splitting | Yes (horizontal + vertical) | Vertical only (limited) |
| Mouse support | Yes | Partial |
| Scripting / automation | Strong | Weaker |
| Plugin ecosystem | Yes (TPM) | No |
| Default on servers | Sometimes | Often (older distros) |
Use screen only if tmux isn’t available and you can’t install it. On any modern system you control, use tmux.
Related: Linux Bash Cheat Sheet | Vim Cheat Sheet | SSH & GPG Cheat Sheet