← Tech Guides

tmux // Terminal Multiplexer

Complete Reference & Cheat Sheet

tmux is a terminal multiplexer that lets you run multiple terminal sessions inside a single window. Detach and reattach sessions, split your screen into panes, and manage windows -- all from the keyboard. Default prefix key: Ctrl+b

QUICK REFERENCE

essential commands at a glance
Prefix key: Ctrl+b — press this first, then the command key

SESSIONS

tmux new -s namenew session
tmux a -t nameattach
tmux lslist sessions
Ctrl+b ddetach
Ctrl+b $rename session
Ctrl+b slist / switch
Ctrl+b ( )prev / next session

WINDOWS

Ctrl+b cnew window
Ctrl+b ,rename window
Ctrl+b &kill window
Ctrl+b n / pnext / prev window
Ctrl+b 0-9select by number
Ctrl+b wchoose window
Ctrl+b llast window

PANES

Ctrl+b %split vertical
Ctrl+b "split horizontal
Ctrl+b arrowsnavigate panes
Ctrl+b zzoom toggle
Ctrl+b xkill pane
Ctrl+b !pane to window
Ctrl+b Spacecycle layouts

COPY MODE (vi)

Ctrl+b [enter copy mode
/ or ?search fwd / back
Spacebegin selection
Entercopy & exit
Ctrl+b ]paste buffer
qexit copy mode
Ctrl+b =choose buffer

MISC

Ctrl+b :command prompt
Ctrl+b ?list key bindings
Ctrl+b tshow clock
Ctrl+b iwindow info
Ctrl+b qshow pane numbers
Ctrl+b ~show messages
Ctrl+b rrefresh client

COMMAND LINE

tmux new -s namenew session
tmux a -t nameattach to session
tmux lslist sessions
tmux kill-session -t namekill session
tmux kill-serverkill everything
tmux source ~/.tmux.confreload config
tmux new -A -s nameattach or create

SESSION MANAGEMENT

create, attach, detach, and manage sessions

Sessions are the top-level container in tmux. Each session holds one or more windows, and persists even after you disconnect. This is what makes tmux invaluable for remote work -- your entire workspace survives network drops.

Creating Sessions

CommandDescription
tmuxStart new unnamed session
tmux newStart new session (alias)
tmux new -s <name>Start new session with a name
tmux new -s <name> -n <win>New session with named first window
tmux new -s <name> -dCreate session in background (detached)
tmux new -A -s <name>Attach if exists, otherwise create

Attaching to Sessions

CommandDescription
tmux attachAttach to last session
tmux attach -t <name>Attach to named session
tmux aShorthand for attach
tmux a -t <name>Shorthand attach to named session
tmux attach -dDetach other clients when attaching

Detaching & Switching

Key BindingCommandDescription
Ctrl+b dtmux detachDetach from current session
Ctrl+b D-Choose which client to detach
Ctrl+b stmux lsList / choose sessions interactively
Ctrl+b (-Switch to previous session
Ctrl+b )-Switch to next session
Ctrl+b L-Switch to last used session

Renaming & Killing Sessions

Key / CommandDescription
Ctrl+b $Rename current session
tmux rename-session -t <old> <new>Rename session from CLI
tmux kill-session -t <name>Kill named session
tmux kill-session -aKill all sessions except current
tmux kill-serverKill tmux server and all sessions

WINDOW MANAGEMENT

tabs within a session

Windows are like tabs within a session. Each window occupies the full terminal screen and can be subdivided into panes. The status bar at the bottom shows all windows in the current session.

Creating & Closing Windows

Key BindingCommandDescription
Ctrl+b ctmux new-windowCreate new window
-tmux new-window -n <name>Create window with name
Ctrl+b &tmux kill-windowKill current window (confirms)

Navigating Windows

Key BindingDescription
Ctrl+b 0-9Select window by number
Ctrl+b nNext window
Ctrl+b pPrevious window
Ctrl+b lLast (previously selected) window
Ctrl+b wChoose window from interactive list
Ctrl+b fFind window by name or content
Ctrl+b 'Prompt for window index to select

Window Operations

Key BindingDescription
Ctrl+b ,Rename current window
Ctrl+b .Move window to another index

PANE MANAGEMENT

split, resize, navigate, and zoom

Panes subdivide a window into multiple terminal regions. You can split horizontally or vertically, resize them, zoom into a single pane, and swap their positions. Panes are where your actual work happens.

Splitting Panes

Key BindingCommandDescription
Ctrl+b "tmux split-windowSplit horizontally (top/bottom)
Ctrl+b %tmux split-window -hSplit vertically (left/right)
The naming is confusing: Ctrl+b " creates a horizontal divider (panes stacked top/bottom), and Ctrl+b % creates a vertical divider (panes side by side).

Navigating Panes

Key BindingDescription
Ctrl+b ←/→/↑/↓Move to pane in that direction
Ctrl+b oCycle to next pane
Ctrl+b ;Move to last (previously active) pane
Ctrl+b qShow pane numbers -- type number to select

Resizing Panes

Key BindingDescription
Ctrl+b Ctrl+←Resize left by 1 cell
Ctrl+b Ctrl+→Resize right by 1 cell
Ctrl+b Ctrl+↑Resize up by 1 cell
Ctrl+b Ctrl+↓Resize down by 1 cell
Ctrl+b Alt+←Resize left by 5 cells
Ctrl+b Alt+→Resize right by 5 cells
Ctrl+b Alt+↑Resize up by 5 cells
Ctrl+b Alt+↓Resize down by 5 cells

Pane Operations

Key BindingDescription
Ctrl+b zToggle zoom (full-screen pane)
Ctrl+b !Break pane out into a new window
Ctrl+b xKill current pane (with confirmation)
Ctrl+b {Swap with previous pane
Ctrl+b }Swap with next pane
Ctrl+b Ctrl+oRotate panes forward
Ctrl+b Alt+oRotate panes backward
Ctrl+b mMark current pane
Ctrl+b MClear marked pane

Pane Layouts

Key BindingLayout
Ctrl+b SpaceCycle through preset layouts
Ctrl+b Alt+1Even-horizontal (all panes side by side)
Ctrl+b Alt+2Even-vertical (all panes stacked)
Ctrl+b Alt+3Main-horizontal (one large on top, rest below)
Ctrl+b Alt+4Main-vertical (one large on left, rest right)
Ctrl+b Alt+5Tiled (all panes equal size)

DEFAULT KEY BINDINGS

complete list, prefix: Ctrl+b
All key bindings below require pressing Ctrl+b first (the prefix), then releasing, then pressing the listed key.

Help & Info

KeyDescription
?List all key bindings
iDisplay window information
qDisplay pane numbers (type number to select)
tShow clock
~Show previous tmux messages

Session Controls

KeyDescription
dDetach client
DChoose client to detach
$Rename session
sChoose session interactively
(Previous session
)Next session
LLast session

Window Controls

KeyDescription
cCreate new window
,Rename current window
&Kill current window
wChoose window interactively
fFind window
nNext window
pPrevious window
lLast (previously selected) window
0-9Select window by number
'Prompt for window index
.Move window to new index

Pane Controls

KeyDescription
"Split pane horizontally (top/bottom)
%Split pane vertically (left/right)
←→↑↓Select pane by direction
oCycle to next pane
;Last active pane
xKill pane
!Break pane to new window
zToggle zoom (full-screen)
{Swap pane with previous
}Swap pane with next
SpaceCycle through layouts
Ctrl+oRotate panes forward
Alt+oRotate panes backward
mMark pane
MClear marked pane
Alt+1Even-horizontal layout
Alt+2Even-vertical layout
Alt+3Main-horizontal layout
Alt+4Main-vertical layout
Alt+5Tiled layout

Copy Mode & Buffers

KeyDescription
[Enter copy mode
]Paste most recent buffer
#List all paste buffers
=Choose buffer to paste
-Delete most recent buffer
PgUpEnter copy mode and scroll up

Miscellaneous

KeyDescription
:Enter command prompt
rRefresh client
Ctrl+zSuspend client
CCustomize mode (options browser)
ESpread panes out evenly
Ctrl+bSend Ctrl+b to the underlying application

COPY MODE

scrolling, searching, and copying text

Copy mode lets you scroll through terminal output, search for text, and copy selections to tmux's paste buffer. Enter with Ctrl+b [. tmux supports both vi and emacs key bindings in copy mode -- set your preference with setw -g mode-keys vi in your config.

To enable vi-style copy mode, add setw -g mode-keys vi to your ~/.tmux.conf. Vi mode is strongly recommended for efficient navigation.

Vi Mode Key Bindings

Navigation
KeyAction
h j k lMove left / down / up / right
wNext word
bPrevious word
0Start of line
$End of line
^First non-blank character
ggTop of history
GBottom of history
HTop of visible screen
MMiddle of visible screen
LBottom of visible screen
{Previous paragraph
}Next paragraph
%Jump to matching bracket
Scrolling
KeyAction
Ctrl+fPage down
Ctrl+bPage up
Ctrl+dHalf page down
Ctrl+uHalf page up
Ctrl+eScroll down one line
Ctrl+yScroll up one line
Searching
KeyAction
/Search forward
?Search backward
nNext search match
NPrevious search match
Selection & Copying
KeyAction
SpaceBegin selection
EnterCopy selection and exit copy mode
EscapeClear selection
vToggle rectangle selection
VSelect entire line
qExit copy mode

Emacs Mode Key Bindings

Navigation
KeyAction
←→↑↓Move cursor
Ctrl+aStart of line
Ctrl+eEnd of line
Ctrl+f / Ctrl+bMove right / left
Ctrl+n / Ctrl+pMove down / up
Alt+fNext word end
Alt+bPrevious word
Alt+<Top of history
Alt+>Bottom of history
Scrolling
KeyAction
PgDn / Ctrl+vPage down
PgUp / Alt+vPage up
Alt+DownHalf page down
Alt+UpHalf page up
Searching & Selection
KeyAction
Ctrl+sSearch forward (incremental)
Ctrl+rSearch backward (incremental)
Ctrl+SpaceBegin selection
Alt+wCopy selection and exit
Ctrl+gClear selection
q / EscapeExit copy mode

CONFIGURATION

~/.tmux.conf customization

tmux reads configuration from ~/.tmux.conf on startup. Changes take effect after reloading. There are four types of options: server, session, window, and pane. Use set for session options and setw (or set-window-option) for window options. Add -g to set globally.

Essential Settings

# Change prefix from Ctrl+b to Ctrl+a
unbind C-b
set -g prefix C-a
bind C-a send-prefix

# Enable mouse mode
set -g mouse on

# Start window/pane numbering at 1
set -g base-index 1
setw -g pane-base-index 1

# Enable vi mode for copy mode
setw -g mode-keys vi

# Increase scrollback buffer
set -g history-limit 10000

# Enable 256 colors
set -g default-terminal "screen-256color"

# Enable true color (24-bit) support
set -ga terminal-features ",xterm-256color:RGB"

# Reduce escape time (important for vim users)
set -sg escape-time 0

# Automatically renumber windows when one is closed
set -g renumber-windows on

# Monitor activity in windows
setw -g monitor-activity on
set -g visual-activity on

# Reload config with prefix+r
bind r source-file ~/.tmux.conf \; display "Config reloaded!"

Custom Key Bindings

# Intuitive split keys
bind | split-window -h
bind - split-window -v
unbind '"'
unbind %

# Switch panes with Alt+arrow (no prefix needed)
bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D

# Vi-style pane navigation with prefix
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

# Vi-style copy mode
bind -T copy-mode-vi v send-keys -X begin-selection
bind -T copy-mode-vi y send-keys -X copy-selection-and-cancel
bind -T copy-mode-vi C-v send-keys -X rectangle-toggle

Status Bar Customization

# Position
set -g status-position bottom

# Colors
set -g status-style 'bg=colour234 fg=colour137'

# Left and right sections
set -g status-left '#[fg=colour233,bg=colour245,bold] #S '
set -g status-right '#[fg=colour233,bg=colour245,bold] %d/%m #[fg=colour233,bg=colour245,bold] %H:%M:%S '

# Window status
setw -g window-status-current-style 'fg=colour1 bg=colour238 bold'
setw -g window-status-current-format ' #I:#W#F '
setw -g window-status-style 'fg=colour9 bg=colour236'
setw -g window-status-format ' #I:#W#F '

# Pane borders
set -g pane-border-style 'fg=colour238'
set -g pane-active-border-style 'fg=colour51'

Common Configuration Options

OptionDescription
set -g prefix <key>Change prefix key
set -g mouse onEnable mouse support
set -g base-index 1Start window numbering at 1
setw -g pane-base-index 1Start pane numbering at 1
setw -g mode-keys viUse vi keys in copy mode
set -g history-limit <n>Set scrollback buffer size
set -g default-terminal <term>Set default terminal type
set -sg escape-time <ms>Set escape key delay
set -g renumber-windows onRenumber windows on close
set -g status-position top|bottomStatus bar position

Reloading Configuration

# From the command line
tmux source-file ~/.tmux.conf

# From within tmux command prompt (Ctrl+b :)
source-file ~/.tmux.conf

Conditional Configuration

# Different settings per tmux version
%if "#{>=:#{version},3.2}"
    set -g status-position top
%else
    set -g status-position bottom
%endif

# Different settings per host
%if "#{==:#{host},laptop}"
    set -g status-style bg=blue
%elif "#{==:#{host},desktop}"
    set -g status-style bg=green
%endif

File Locations

PathDescription
~/.tmux.confUser configuration file
/etc/tmux.confSystem-wide configuration
/tmp/tmux-UID/defaultServer socket

SCRIPTING & AUTOMATION

send-keys, capture-pane, session scripts

tmux can be fully controlled from the command line, making it ideal for scripting automated workspace setups. The two most powerful scripting commands are send-keys (send input to a pane) and capture-pane (read output from a pane).

send-keys

Programmatically send keystrokes to a target pane. Target format: session:window.pane

# Basic usage
tmux send-keys -t <target> '<command>' Enter

# Send command to specific session:window.pane
tmux send-keys -t mysession:0.0 'ls -la' Enter
tmux send-keys -t 0:1 'vim file.txt' Enter

# Send to pane by ID
tmux send-keys -t %2 'echo hello' Enter

# Send text without pressing Enter
tmux send-keys -t 0 'text without executing'

# Send literal text (no key interpretation)
tmux send-keys -l 'text with special chars'

capture-pane

Capture the visible contents (or history) of a pane for logging or automation.

# Print pane contents to stdout
tmux capture-pane -p

# Capture to a named buffer
tmux capture-pane -b buffer-name

# Capture with scrollback history (last 1000 lines)
tmux capture-pane -S -1000 -p

# Capture to a file
tmux capture-pane -p > output.txt

# Capture with ANSI escape sequences
tmux capture-pane -e -p

# Capture specific line range
tmux capture-pane -S 0 -E 50 -p

Session Startup Script

Create a reusable script that sets up your entire workspace.

#!/bin/bash
SESSION="dev"

# Create session (detached)
tmux new-session -d -s $SESSION

# Window 0: Editor with side terminal
tmux rename-window -t $SESSION:0 'editor'
tmux split-window -h -t $SESSION:0
tmux split-window -v -t $SESSION:0.1

# Send commands to each pane
tmux send-keys -t $SESSION:0.0 'vim' Enter
tmux send-keys -t $SESSION:0.1 'npm run dev' Enter
tmux send-keys -t $SESSION:0.2 'git status' Enter

# Window 1: Server
tmux new-window -t $SESSION:1 -n 'server'
tmux send-keys -t $SESSION:1 'cd ~/server && npm start' Enter

# Select starting window and pane
tmux select-window -t $SESSION:0
tmux select-pane -t $SESSION:0.0

# Attach
tmux attach-session -t $SESSION

Useful Scripting Patterns

# Create or attach (idempotent)
tmux new-session -A -s mysession

# Check if session exists before creating
tmux has-session -t mysession 2>/dev/null
if [ $? != 0 ]; then
    tmux new-session -s mysession
fi

# Kill all sessions except one
tmux kill-session -a -t keep-this-one

# List all panes across all sessions
tmux list-panes -a -F "#{session_name}:#{window_index}.#{pane_index}"

# Run command in all panes of current window
for pane in $(tmux list-panes -F '#P'); do
    tmux send-keys -t $pane "ls -la" Enter
done

# Capture output of a command
tmux send-keys -t mysession:0.0 'date' Enter
sleep 1
tmux capture-pane -t mysession:0.0 -p | tail -1

Format Strings

tmux format strings let you extract structured information from sessions, windows, and panes.

# Sessions with window count
tmux list-sessions -F "#{session_name}: #{session_windows} windows"

# Windows with pane count
tmux list-windows -F "#{window_index}: #{window_name} [#{window_panes} panes]"

# Panes with dimensions and running command
tmux list-panes -F "Pane #{pane_index}: #{pane_current_command} (#{pane_width}x#{pane_height})"

PRO TIPS

advanced features and power-user tricks

Synchronize Panes

Type the same command in all panes of a window simultaneously. Extremely useful for running the same command on multiple servers.

# Toggle on/off from command prompt (Ctrl+b :)
:setw synchronize-panes on
:setw synchronize-panes off

# From CLI
tmux setw synchronize-panes on

# Add toggle binding to .tmux.conf
bind S setw synchronize-panes

Hooks

Execute tmux commands automatically when events occur.

# Notification when a new window is created
set-hook -g after-new-window 'display "New window created"'

# Auto-tile after splitting
set-hook -g after-split-window 'select-layout tiled'

# Refresh after rename
set-hook -g after-rename-window 'refresh-client -S'

# List all hooks
show-hooks -g

Nested tmux Sessions

When running tmux inside tmux (e.g., local + remote), use different prefix keys to avoid conflicts.

# Outer session uses Ctrl+a as prefix
set -g prefix C-a

# Inner session keeps default Ctrl+b
# To send commands to inner: press Ctrl+a, then Ctrl+b, then the key
# Or use Ctrl+b Ctrl+b to send prefix to inner app

Session Groups

Link sessions together so they share the same set of windows. Each session can view different windows independently.

# Create main session
tmux new-session -s main

# Create linked session (shares windows with main)
tmux new-session -t main -s secondary

# Both sessions share windows
# Each can view a different window independently

Pipe Pane Output

Log all output from a pane to a file in real time.

# Start logging pane to file
:pipe-pane -o 'cat >> ~/output.log'

# Stop logging
:pipe-pane

# Toggle binding for .tmux.conf
bind P pipe-pane -o 'cat >> ~/tmux-#I-#P.log' \; display 'Toggled logging'

Clipboard Integration

Copy tmux buffer directly to your system clipboard.

# Linux (X11)
bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel 'xclip -in -selection clipboard'

# macOS
bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel 'pbcopy'

# WSL (Windows Subsystem for Linux)
bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel 'clip.exe'

Break & Join Panes

Move panes between windows without losing their state.

# Break pane out to its own window
# Key: Ctrl+b !

# Join a pane from another window into current
tmux join-pane -s 2.0 -t 1.0

# Mark a pane, navigate to destination, then join
# Ctrl+b m    (mark pane)
# navigate to target window
tmux join-pane    # joins the marked pane here

Display Pane Numbers Longer

Give yourself more time to read pane numbers when using Ctrl+b q.

# Show pane numbers for 4 seconds (default is 1s)
set -g display-panes-time 4000

Respawn Pane

Restart a dead or exited pane without destroying the layout.

# Respawn a specific pane
tmux respawn-pane -k -t 0

# Add binding to .tmux.conf
bind R respawn-pane -k

Monitoring Windows

# Alert when a window has activity
:setw monitor-activity on

# Alert when a window has been silent for 30s
:setw monitor-silence 30

# Visual notification in status bar
set -g visual-activity on

Custom Layouts with Exact Sizing

# Split with specific percentage
tmux split-window -h -p 30    # 70/30 horizontal split
tmux split-window -v -p 50    # 50/50 vertical split

# Save and restore layouts
tmux list-windows -F "#{window_layout}" > ~/tmux-layout.txt
tmux select-layout "$(cat ~/tmux-layout.txt)"

Environment Variables

# Set environment variable for session
tmux set-environment VAR value

# Show all environment variables
tmux show-environment

# Use in new window commands
tmux new-window -n "test" 'echo $VAR'