tmux
Manage persistent terminal sessions, windows, panes, copy mode, configuration, and automation with tmux.
Setup
Install tmux, verify its version, and start a named session.
Install tmux with a platform package manager and create a session.
# macOS
brew install tmux
# Ubuntu or Debian
sudo apt update
sudo apt install tmuxStart and Inspect
Start tmux and inspect the running server.
Create a new session or attach to an existing one.
tmuxInspect sessions, clients, windows, and panes.
tmux list-sessionsSessions
Create, name, attach to, and remove sessions.
Create a named session and rename it later.
tmux new-session -s apiReconnect clients without stopping running programs.
tmux attach-session -t backendStop one session or every session except one.
tmux kill-session -t backendWindows
Create and organize terminal workspaces within a session.
Add a window and give it a useful name.
# Inside tmux
# Ctrl-b cMove between windows and change their indexes.
# Ctrl-b n next
# Ctrl-b p previous
# Ctrl-b 0 window zeroPanes
Split windows and control individual terminals.
Split the current pane vertically or horizontally.
# Ctrl-b % left and right
# Ctrl-b " top and bottomSelect panes by direction, number, or target.
# Ctrl-b Arrow select by direction
# Ctrl-b o select next paneAdjust pane space or focus on one pane.
# Ctrl-b z toggle zoom
# Ctrl-b x kill paneLayouts
Apply and preserve standard pane arrangements.
Cycle or select a built-in pane layout.
# Ctrl-b Space cycle layoutsTargets and Commands
Address tmux objects and run commands precisely.
Address sessions, windows, and panes.
session:window.pane
work:editor.1Run tmux commands interactively or in sequence.
# Ctrl-b :
new-window -n logsCopy Mode and Buffers
Navigate scrollback, copy text, and manage paste buffers.
Browse pane history without sending input to the app.
# Ctrl-b [ enter copy mode
# q exit copy modeCopy a selection into a tmux buffer and paste it.
# In vi copy mode: Space, move, Enter
# Ctrl-b ] pasteConfiguration
Set persistent options and reload configuration.
Store settings and load changes without restarting.
# ~/.tmux.conf
set -g mouse onSet server, session, window, or pane behavior.
set -g mouse on
set -g history-limit 50000Key Bindings
Change the prefix and add focused shortcuts.
Replace Ctrl-b while preserving prefix passthrough.
unbind C-b
set -g prefix C-a
bind C-a send-prefixBind keys with or without the prefix.
bind | split-window -h
bind - split-window -vMouse and Status Line
Enable pointer support and customize visible context.
Select panes, resize borders, and scroll with the mouse.
set -g mouse onShow session context using formats and styles.
set -g status-left '#S '
set -g status-right '%H:%M'Formats and Automation
Query state and react to tmux events.
Print tmux state for scripts and status content.
tmux display-message -p '#S:#I.#P'Run a tmux command after a server event.
set-hook -g session-created 'display-message "Session created"'Reconnect to a named tmux session over SSH.
ssh server -t 'tmux new-session -A -s work'Troubleshooting
Inspect configuration and recover from common problems.
Check keys, options, messages, and pane identity.
tmux list-keys
tmux show-options -g