tmux
Session Management
Sessions
# Create named session
tmux new-session -s infra
tmux new -s lab -d # detached
# List sessions
tmux list-sessions # or tmux ls
# Attach
tmux attach -t infra # or tmux a -t infra
tmux attach -t infra -d # detach others first
# Detach from inside
# prefix + d (default prefix: Ctrl-b)
# Kill session
tmux kill-session -t lab
tmux kill-server # kill everything
Windows and Panes
Window operations (prefix +)
# Windows
# c create window
# , rename window
# n/p next/previous window
# 0-9 jump to window by number
# w list windows (interactive)
# & kill window
# Panes
# % vertical split
# " horizontal split
# o cycle panes
# ; last active pane
# x kill pane
# z toggle pane zoom (fullscreen)
# {/} swap pane left/right
# Space cycle layouts
Pane navigation and resizing
# Arrow keys to navigate panes (prefix + arrow)
# Resize: prefix + Ctrl-arrow (or Alt-arrow)
# Resize from command mode (prefix + :)
# resize-pane -D 10 # down 10 rows
# resize-pane -R 20 # right 20 cols
# Break pane to own window
# prefix + !
# Join pane from another window
tmux join-pane -s 2 -t 1 # move window 2's pane to window 1
# Synchronize panes (type in all panes simultaneously)
# prefix + : → setw synchronize-panes on
Copy Mode
Scrollback and copy
# Enter copy mode: prefix + [
# Navigate with vi keys (if set -g mode-keys vi)
# Start selection: Space (or v in vi mode)
# Copy: Enter (or y in vi mode)
# Paste: prefix + ]
# Search in copy mode: / or ? (vi mode)
# Increase scrollback
# set -g history-limit 50000
Configuration Essentials
~/.tmux.conf patterns
# Set prefix to Ctrl-a (screen-style)
unbind C-b
set -g prefix C-a
bind C-a send-prefix
# Vi mode
set -g mode-keys vi
set -g status-keys vi
# Mouse support
set -g mouse on
# Start windows/panes at 1 (not 0)
set -g base-index 1
setw -g pane-base-index 1
# Reload config
bind r source-file ~/.tmux.conf \; display "Reloaded"
# True color support
set -g default-terminal "tmux-256color"
set -ag terminal-overrides ",xterm-256color:RGB"
# Reduce escape delay (important for Neovim)
set -sg escape-time 10
# Focus events (for Neovim autoread)
set -g focus-events on
CLI Operations
tmux from the shell
# Send keys to a running session
tmux send-keys -t infra:0 "ls -la" Enter
# Capture pane output
tmux capture-pane -t infra:0 -p > /tmp/output.txt
# Run command in new window
tmux new-window -t infra "htop"
# Scripted layout
tmux new-session -d -s dev
tmux send-keys -t dev "nvim" Enter
tmux split-window -h -t dev
tmux send-keys -t dev "git status" Enter
tmux split-window -v -t dev
tmux attach -t dev