TMUX¶
Terminal multiplexer. Split terminals, create windows, detach/reattach sessions. SSH connection drops? Session survives. Long-running processes? Background them. Multiple terminals? One window. The Swiss Army knife of terminal management.
Why TMUX
Persistent sessions survive disconnects, split panes for multi-tasking, window management without GUI, pair programming over SSH, scriptable layouts.
Quick Start¶
macOS:
brew install tmux
Ubuntu/Debian:
sudo apt install tmux
Arch Linux:
sudo pacman -S tmux
Verify:
tmux -V
# tmux 3.3a
Start session:
# New session
tmux
# Named session
tmux new -s work
# New session with name and window
tmux new -s dev -n editor
Detach and attach:
# Inside tmux, detach with: Ctrl+b then d
# List sessions
tmux ls
# Attach to session
tmux attach -t work
# Attach to last session
tmux a
Kill sessions:
# Kill specific session
tmux kill-session -t work
# Kill all sessions
tmux kill-server
Prefix key: Ctrl+b (all commands start with this)
Session management: - Ctrl+b d - Detach session - Ctrl+b $ - Rename session - Ctrl+b s - List sessions
Window management: - Ctrl+b c - Create window - Ctrl+b , - Rename window - Ctrl+b w - List windows - Ctrl+b n - Next window - Ctrl+b p - Previous window - Ctrl+b 0-9 - Switch to window number - Ctrl+b & - Kill window
Pane management: - Ctrl+b % - Split vertically - Ctrl+b " - Split horizontally - Ctrl+b arrow - Navigate panes - Ctrl+b o - Next pane - Ctrl+b x - Kill pane - Ctrl+b z - Zoom/unzoom pane - Ctrl+b { - Move pane left - Ctrl+b } - Move pane right
Copy mode: - Ctrl+b [ - Enter copy mode - Space - Start selection - Enter - Copy selection - Ctrl+b ] - Paste
Configuration¶
Config file: ~/.tmux.conf
# ============================================
# TMUX CONFIGURATION
# ============================================
# Change 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
# Split panes using | and - (more intuitive)
bind | split-window -h
bind - split-window -v
unbind '"'
unbind %
# Switch panes using Alt+arrow without prefix
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
# Enable mouse mode (tmux 2.1+)
set -g mouse on
# Don't rename windows automatically
set-option -g allow-rename off
# Start windows and panes at 1, not 0
set -g base-index 1
setw -g pane-base-index 1
# Reload config with prefix + r
bind r source-file ~/.tmux.conf \; display "Config reloaded!"
# Increase scrollback buffer
set-option -g history-limit 10000
# Fix colors
set -g default-terminal "screen-256color"
set -ga terminal-overrides ",xterm-256color:Tc"
# Status bar
set -g status-position bottom
set -g status-bg colour234
set -g status-fg colour137
set -g status-left ''
set -g status-right '#[fg=colour233,bg=colour241,bold] %d/%m #[fg=colour233,bg=colour245,bold] %H:%M:%S '
set -g status-right-length 50
set -g status-left-length 20
# Active window title colors
setw -g window-status-current-style 'fg=colour81 bg=colour238 bold'
setw -g window-status-current-format ' #I#[fg=colour250]:#[fg=colour255]#W#[fg=colour50]#F '
# Inactive window title colors
setw -g window-status-style 'fg=colour138 bg=colour235'
setw -g window-status-format ' #I#[fg=colour237]:#[fg=colour250]#W#[fg=colour244]#F '
# Pane border colors
set -g pane-border-style 'fg=colour238'
set -g pane-active-border-style 'fg=colour51'
# Vi mode for copy
setw -g mode-keys vi
bind-key -T copy-mode-vi v send -X begin-selection
bind-key -T copy-mode-vi y send -X copy-selection-and-cancel
Apply configuration:
# Reload inside tmux
# Press: Ctrl+b then :
source-file ~/.tmux.conf
# Or use the r binding from config above
# Press: Ctrl+a then r
Common Workflows¶
Development Session¶
# Create development session
tmux new -s dev
# Inside tmux:
# Ctrl+b | - Split vertically (code left, terminal right)
# Ctrl+b - - Split horizontally (logs bottom)
# Ctrl+b arrow - Navigate between panes
# Result: 3-pane layout
# +------------------+----------+
# | | |
# | Code Editor | Terminal |
# | | |
# +------------------+----------+
# | Logs / Tests |
# +-----------------------------+
Remote Server Monitoring¶
# SSH to server
ssh user@server
# Start tmux session
tmux new -s monitoring
# Create windows for different services
# Ctrl+b c - New window for logs
# Ctrl+b c - New window for htop
# Ctrl+b c - New window for docker
# Detach (Ctrl+b d) and logout
# SSH back later, reattach: tmux a -t monitoring
Pair Programming¶
# Person A creates session
tmux new -s pair
# Person B connects (same user or separate account)
tmux attach -t pair
# Both see the same screen, both can type
# Perfect for remote pair programming
Advanced Commands¶
# Session management
tmux new -s name # New named session
tmux attach -t name # Attach to session
tmux switch -t name # Switch to session
tmux ls # List sessions
tmux kill-session -t name # Kill session
tmux rename-session -t old new # Rename session
# Window management
tmux new-window -n name # New named window
tmux select-window -t :0 # Select window by index
tmux rename-window name # Rename current window
tmux move-window -t :3 # Move window to index 3
tmux swap-window -s 2 -t 1 # Swap windows 2 and 1
# Pane management
tmux split-window -h # Split horizontal
tmux split-window -v # Split vertical
tmux select-pane -t :.+ # Select next pane
tmux resize-pane -D 10 # Resize down 10 cells
tmux resize-pane -U 10 # Resize up 10 cells
tmux resize-pane -L 10 # Resize left 10 cells
tmux resize-pane -R 10 # Resize right 10 cells
tmux swap-pane -s 0 -t 1 # Swap panes
# Layouts
tmux select-layout even-horizontal # Evenly split horizontal
tmux select-layout even-vertical # Evenly split vertical
tmux select-layout main-horizontal # Main pane top
tmux select-layout main-vertical # Main pane left
tmux select-layout tiled # Tile all panes
Pro Tips¶
- Use Ctrl+a prefix - Easier to reach than Ctrl+b (like GNU Screen)
- Mouse mode is OK - Don't let purists shame you, it's convenient
- Name your sessions -
tmux new -s projectbeatstmux-0 - Use zoom -
Ctrl+b zto fullscreen a pane temporarily - Copy mode is powerful -
Ctrl+b [then navigate with vi keys - Detach often - Long-running tasks? Detach and close terminal
- Save layouts - Use scripts to recreate window/pane setups
- Resurrect plugin - Save/restore entire tmux environments
- Synchronize panes -
Ctrl+b :setw synchronize-panes- type in all panes at once - Use tmuxinator - Define project layouts in YAML
Common Gotchas¶
- Colors broken - Set
TERM=screen-256colororxterm-256colorin config - Nested tmux sessions - Don't start tmux inside tmux (detach first)
- Clipboard doesn't work - Install
reattach-to-user-namespace(macOS) orxclip(Linux) - Mouse scroll not working - Enable mouse mode:
set -g mouse on - Prefix key conflicts - Ctrl+b conflicts with vim? Change to Ctrl+a
- Can't resize panes - Check mouse mode, or use
Ctrl+b arrow+ arrow keys - Session persists after reboot - Use tmux-continuum plugin for auto-save/restore
- Status bar ugly - Use powerline or tmux themes (tokyo-night, dracula)
- Too many sessions - Run
tmux ls, clean up withtmux kill-session -t name
Resources¶
Official: - TMUX Manual - Complete reference - GitHub - Source code and issues - Wiki - Community wiki
Plugins: - TPM (Tmux Plugin Manager) - Plugin manager - tmux-resurrect - Save/restore sessions - tmux-continuum - Auto-save sessions - tmux-sensible - Sensible defaults
Tools: - tmuxinator - Manage complex tmux sessions - tmuxp - Python-based tmux session manager
Learning: - tmux Cheat Sheet - Quick reference - The Tao of tmux - Free book
Communities: - r/tmux - Reddit community
Last Updated: 2026-02-03
Tags: tmux, terminal-multiplexer, terminal, cli, session-management, development-tools, productivity