Mastering tmux (Power-User Guide)
Go beyond the basics with tmux: persistent sessions, pane layouts, vi copy mode, a production tmux.conf, session scripting, and TPM plugins including resurrect.
Before you start
- ▸A terminal emulator with 256-color or TrueColor support (kitty, alacritty, foot, or GNOME Terminal)
- ▸Basic shell familiarity — you should be comfortable editing files and running commands
- ▸sudo or root access only for the install step; everything else runs as your normal user
- ▸Git installed if you plan to use TPM for plugin management
tmux is a terminal multiplexer that lets you run multiple programs inside a single terminal window, detach from them, and reattach later — even over SSH. Once your workflow depends on it, you won't go back. This guide goes beyond the basics: persistent sessions, window/pane layouts, copy mode, scripting with tmux new-session, the plugin ecosystem via TPM, and a production-ready ~/.tmux.conf.
Installation
tmux is in every major distro's repositories. Install the version that ships with your distro; anything 3.2+ covers everything here.
# Debian / Ubuntu
sudo apt install tmux
# Fedora / RHEL 9+ / Rocky
sudo dnf install tmux
# Arch
sudo pacman -S tmux
tmux -V # confirm version, e.g. tmux 3.3a
Sessions: the Outermost Container
A session is the top-level object. It persists after you detach, survives SSH disconnections, and can be shared between users.
Creating and naming sessions
tmux new-session -s work # start a named session called "work"
tmux new -s deploy # shorthand
Detaching and reattaching
# Inside tmux: detach with the default prefix then d
# Prefix is Ctrl-b by default
# Press Ctrl-b, then d
tmux ls # list sessions from outside tmux
tmux attach -t work # reattach by name
tmux a # attach to last used session
Killing sessions
tmux kill-session -t work
tmux kill-server # destroy everything
Windows: Tabs Inside a Session
A session holds one or more windows, each occupying the full terminal like a browser tab. The status bar at the bottom shows them.
| Key | Action |
|---|---|
| Prefix + c | Create new window |
| Prefix + , | Rename current window |
| Prefix + n / p | Next / previous window |
| Prefix + 0–9 | Jump to window by index |
| Prefix + & | Kill current window |
| Prefix + w | Interactive window list |
# From the command line, create a window with a specific name and command
tmux new-window -t work -n logs "tail -F /var/log/syslog"
Panes: Splits Inside a Window
Panes split a window into regions. Each pane runs its own shell or program independently.
| Key | Action |
|---|---|
| Prefix + % | Split vertically (side by side) |
| Prefix + " | Split horizontally (top / bottom) |
| Prefix + Arrow | Move between panes |
| Prefix + z | Zoom (fullscreen) a pane / unzoom |
| Prefix + x | Kill pane |
| Prefix + { / } | Swap pane with previous / next |
| Prefix + Space | Cycle through built-in layouts |
# Resize panes from the command line (useful in scripts)
tmux resize-pane -t work:editor.0 -R 20 # move right edge 20 cells right
Copy Mode: Scrollback and Clipboard
Copy mode lets you scroll back through output and yank text. By default tmux uses emacs-style keys; switching to vi mode is strongly recommended.
# Add to ~/.tmux.conf
setw -g mode-keys vi
Enter copy mode with Prefix + [. Navigate with hjkl, start a selection with v (after the config below), copy with y, paste with Prefix + ].
# Extend ~/.tmux.conf for vi copy mode bindings
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi y send-keys -X copy-selection-and-cancel
bind-key -T copy-mode-vi C-v send-keys -X rectangle-toggle
Piping to the system clipboard
On Wayland use wl-copy; on X11 use xclip or xsel. The tmux-yank plugin (covered below) handles this automatically.
# Manual approach — pipe a pane's buffer to wl-copy
tmux show-buffer | wl-copy
A Production-Ready ~/.tmux.conf
Drop this in ~/.tmux.conf. It changes the prefix to Ctrl-a (screen-style), enables true color, sensible mouse support, and sets 10 000-line history.
# ~/.tmux.conf
# Prefix
unbind C-b
set -g prefix C-a
bind C-a send-prefix
# Terminal & color
set -g default-terminal "tmux-256color"
set -ag terminal-overrides ",xterm-256color:RGB"
# General
set -g history-limit 10000
set -g mouse on
set -g base-index 1 # windows start at 1, not 0
setw -g pane-base-index 1
set -g renumber-windows on # close window 2 of 1,2,3 → becomes 1,2
set -sg escape-time 0 # no delay after Escape (important for Neovim)
# Vi copy mode
setw -g mode-keys vi
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi y send-keys -X copy-selection-and-cancel
bind-key -T copy-mode-vi C-v send-keys -X rectangle-toggle
# Intuitive split bindings (keep current path)
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
bind c new-window -c "#{pane_current_path}"
# Reload config
bind r source-file ~/.tmux.conf \; display "Config reloaded"
# Status bar
set -g status-position top
set -g status-style "bg=#1e1e2e,fg=#cdd6f4"
set -g status-left " #S "
set -g status-right " %H:%M %d-%b "
set -g window-status-current-style "fg=#89b4fa,bold"
Reload without restarting:
tmux source-file ~/.tmux.conf
# or with the binding above: Prefix + r
Scripting Sessions
Automate your dev environment so one command rebuilds your exact layout every morning.
#!/usr/bin/env bash
# ~/bin/dev-session.sh — launch a standard dev workspace
SESSION="dev"
# Don't create a duplicate session
tmux has-session -t "$SESSION" 2>/dev/null && tmux attach -t "$SESSION" && exit 0
tmux new-session -d -s "$SESSION" -n editor
tmux send-keys -t "$SESSION:editor" "nvim ." Enter
tmux new-window -t "$SESSION" -n server
tmux send-keys -t "$SESSION:server" "npm run dev" Enter
tmux new-window -t "$SESSION" -n git
tmux split-window -t "$SESSION:git" -v
tmux send-keys -t "$SESSION:git.1" "git log --oneline -20" Enter
tmux send-keys -t "$SESSION:git.2" "watch -n5 git status" Enter
tmux select-window -t "$SESSION:editor"
tmux attach -t "$SESSION"
chmod +x ~/bin/dev-session.sh
~/bin/dev-session.sh
Plugins with TPM
The Tmux Plugin Manager (TPM) handles installation and updates. Clone it first:
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
Add the following block to the bottom of ~/.tmux.conf:
# Plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible' # sane defaults
set -g @plugin 'tmux-plugins/tmux-yank' # system clipboard in copy mode
set -g @plugin 'tmux-plugins/tmux-resurrect' # save/restore sessions across reboots
set -g @plugin 'tmux-plugins/tmux-continuum' # auto-save every 15 min
set -g @continuum-restore 'on'
# Keep this line last
run '~/.tmux/plugins/tpm/tpm'
Reload the config, then press Prefix + I (capital i) to install plugins. Update them later with Prefix + U.
tmux-resurrect saves pane contents and running programs. Save manually with Prefix + Ctrl-s, restore with Prefix + Ctrl-r. With tmux-continuum enabled, saving is automatic.
Verification
# Confirm sessions, windows, and panes are all visible
tmux list-sessions
tmux list-windows -t dev
tmux list-panes -t dev:git
Output will look similar to:
dev: 3 windows (created Mon Jun 2 09:14:22 2025)
dev:git: 2 panes [220x50] [layout even-vertical]
Troubleshooting
- Colors look wrong in Neovim or other TUI apps. Make sure your terminal emulator supports TrueColor and that
TERM=xterm-256coloroutside tmux. Theterminal-overridesline in the config above passes RGB through correctly. - Escape key has a noticeable delay. Set
set -sg escape-time 0in~/.tmux.conf. This is critical for Neovim and other vi-style tools. - tmux-yank doesn't copy on Wayland. Install
wl-clipboard(apt install wl-clipboard/dnf install wl-clipboard). tmux-yank detects it automatically. - Session not surviving reboot. tmux-resurrect only saves state; it doesn't auto-start tmux on boot. Add your session script to your
~/.bashrcor a systemd user unit if you need that behavior. - Nested tmux (local + remote SSH). Press the prefix twice to send it to the inner session. Set a different prefix on one of them, or use
Prefix + F12toggle approaches found in the tmux wiki.
Frequently asked questions
- What is the difference between a tmux session, window, and pane?
- A session is the outermost container that persists when detached. Each session holds one or more windows (like browser tabs). Each window can be split into multiple panes, each running its own process.
- How do I keep my tmux sessions alive after a reboot?
- Install tmux-resurrect via TPM. Save your layout with Prefix + Ctrl-s before rebooting, then restore it with Prefix + Ctrl-r after. tmux-continuum automates the save step every 15 minutes.
- Why does copy-paste not work with my system clipboard inside tmux?
- tmux has its own internal buffer. The tmux-yank plugin bridges this to your system clipboard automatically; on Wayland it needs wl-clipboard installed, on X11 it needs xclip or xsel.
- How do I send commands to a pane without switching to it?
- Use tmux send-keys -t <session>:<window>.<pane> "command" Enter from any terminal, including from scripts or other panes. This is the foundation of tmux automation.
- Can I use tmux inside an SSH session and still have a working prefix?
- Yes. When you have nested tmux sessions (local and remote), press the prefix twice to pass it to the inner session, or configure a distinct prefix (for example Ctrl-a locally, Ctrl-b remotely) so they don't conflict.
Related guides
Bash Arrays and Associative Arrays
Master bash indexed and associative arrays: declaration, element access, looping, mapfile, namerefs, and practical patterns for real scripting work.
Bash Functions and Variable Scoping
Master Bash function scoping with local variables, source-based libraries, correct use of return codes, and array passing techniques including namerefs.
Bash Loops: for, while and until
Learn all three Bash loop types — for, while, and until — with practical, copy-paste examples covering file iteration, counting, polling, and safe line reading.
Bash Scripting for Beginners
Learn Bash scripting from scratch: shebang lines, variables, conditionals, loops, and arguments, plus a real backup script to tie it all together.