Cheatsheets

Tmux

Tmux

Tmux is a terminal multiplexer that allows you to manage multiple terminal sessions, windows, and panes within a single screen. Essential commands for session, window, and pane management.

7 Categories 20 Sections 38 Examples
Tmux Terminal Multiplexer Sessions Windows Panes Development Tools

Getting Started

Start using tmux and learn basic concepts

Starting Tmux

Launch tmux and create your first session

Start tmux without session name

Launches tmux and creates a new default session (session 0).

Code
Terminal window
# Start a tmux session
tmux
# Start tmux with UTF8 support
tmux -u
# Start with specific socket
tmux -S ~/.tmux.socket
Execution
Terminal window
tmux
Output
Terminal window
[new session created]
  • Useful for quick sessions you don't plan to keep
  • Creates session with numeric identifier
  • Can reattach with tmux attach

Create named session

Creates a new named tmux session for better organization and easy identification.

Code
Terminal window
# Create new session with specific name
tmux new -s mysession
# Create named session detached
tmux new -s work -d
# Create with shell command
tmux new -s dev -d "cd ~/projects && bash"
Execution
Terminal window
tmux new -s development
Output
Terminal window
[new session created - development]
  • Named sessions are easier to manage than numbered
  • -d flag starts session detached (background)
  • Can start in specific directory with shell commands

Basic Concepts

Understand tmux structure and terminology

Understanding session, window, and pane hierarchy

Tmux organizes screen space into sessions containing windows, which contain panes.

Code
Session (development)
├── Window 0 (editor)
│ ├── Pane 0 (active)
│ └── Pane 1
├── Window 1 (terminal)
│ └── Pane 0
└── Window 2 (build)
├── Pane 0
├── Pane 1
└── Pane 2
Execution
Terminal window
tmux list-sessions && tmux list-windows
Output
Terminal window
development: 2 windows
0: editor- (2 panes)
1: terminal- (1 pane)
  • Session contains multiple windows
  • Window contains multiple panes
  • Each pane is a separate terminal shell

Check tmux server status

View active sessions and tmux configuration details.

Code
Terminal window
# List all sessions
tmux ls
# Get detailed session info
tmux info
# Show version
tmux -V
Execution
Terminal window
tmux ls
Output
Terminal window
development: 2 windows (80x24)
work: 1 window (120x30)
  • Useful for checking what's running before attaching
  • Shows terminal dimensions for each session

Help and Command Mode

Access built-in help and run commands

Access help and keybindings

Access comprehensive help system and keybinding references within tmux.

Code
Terminal window
# Display keybindings help (in tmux)
C-b ?
# Enter command mode
C-b :
# List keybindings from shell
tmux list-keys
# List all commands
tmux list-commands
Execution
Terminal window
tmux list-keys | head -20
Output
Terminal window
bind-key -T prefix C-b send-keys -X send-prefix
bind-key -T prefix C-c new-window
bind-key -T prefix C-d detach-client
  • C-b is the default prefix key
  • Command mode allows advanced operations
  • [object Object]

Run commands and display help

Display tmux configuration and useful information overlays.

Code
Terminal window
# In tmux, run command to show message
C-b :
# Display clock in session
C-b t
# Show pane numbers
C-b q
# Exit help or clock press any key
Execution
Terminal window
tmux show-options -g
Output
Terminal window
aggressive-resize off
allow-same-window on
base-index 0
bell-action any
  • [object Object]
  • [object Object]
  • Exit overlays with any key or Escape

Sessions

Work with tmux sessions for isolated workspaces

Create and Attach Sessions

Create new sessions and attach to existing ones

Create and attach to new session

Creates a new named session and attaches immediately unless using -d flag.

Code
Terminal window
# Create new session with default name
tmux new -s mysession
# Create session in background (detached)
tmux new -s background -d
# Create session and run command
tmux new -s nodejs -d "node server.js"
# Create with specific working directory
tmux new -s project -d -c ~/projects/myapp
Execution
Terminal window
tmux new -s devwork
Output
Terminal window
[new session created - devwork]
  • Without -d, you're immediately attached to the new session
  • -d useful for automation and batch operations
  • -c sets initial working directory

Attach to existing session

Connects to an existing session, restoring the full terminal state.

Code
Terminal window
# Attach to session by name
tmux attach -t mysession
# Attach to last session
tmux attach
# Attach to session by number
tmux attach -t 0
# Attach read-only
tmux attach -t session -r
Execution
Terminal window
tmux attach -t development
Output
Terminal window
[attached to development session]
  • Must use exact session name or number
  • -r flag makes it read-only (no input)
  • Default is most recently used session

Session Switching and Management

Switch between sessions and manage multiple sessions

Switch between sessions

Quickly switch between different sessions from command line or interactively.

Code
Terminal window
# Switch to named session
tmux switch -t mysession
# From inside tmux, cycle through sessions
C-b ( # Previous session
C-b ) # Next session
# List and select session interactively
tmux choose-session
Execution
Terminal window
tmux switch -t work
Output
Terminal window
[switched to work session]
  • C-b ( and ) cycle through open sessions
  • Useful for toggling between two sessions

List and manage sessions

View all active sessions, rename, and remove sessions as needed.

Code
Terminal window
# List all sessions
tmux ls
# or
tmux list-sessions
# Rename session
tmux rename-session -t old newname
# Kill specific session
tmux kill-session -t sessionname
# Kill all sessions except current
tmux kill-session -t '!^'
Execution
Terminal window
tmux ls
Output
Terminal window
development: 3 windows
work: 2 windows
testing: 1 window (current)
  • Sessions persist until explicitly killed or tmux server stops
  • Renaming helps organize long-running sessions
  • Kill-session useful for cleanup after pairing sessions

Detach and Reattach

Detach from sessions and manage disconnections

Detach from session

Safely detach from session, keeping it running in background.

Code
Terminal window
# Detach from current session (in tmux)
C-b d
# Force detach all clients except specified
tmux detach-client -t session -a
# Detach all clients from all sessions
tmux kill-server
Execution
Terminal window
tmux detach-client -t development
Output
Terminal window
[detached from development]
  • C-b d is most common way to detach
  • Session continues running after detach
  • Useful for keeping processes running over SSH

Manage connections and windows

View client connections and session metadata.

Code
Terminal window
# List all clients connected to session
tmux list-clients
# Details about specific session
tmux display-message -t session -p
# Show session activity
tmux list-clients -t session
Execution
Terminal window
tmux list-clients
Output
Terminal window
/dev/pts/0: 0 (80 x 24) [UTF8]
/dev/pts/1: 1 (120 x 30) [UTF8]
  • Multiple clients can be attached to same session
  • Useful for pair programming
  • Different connections can have different window sizes

Windows

Manage multiple windows within a tmux session

Create and Navigate Windows

Create new windows and move between them

Create new window

Creates new window in current or specified session and switches to it.

Code
Terminal window
# Create new window (in tmux)
C-b c
# Create window with name
C-b : new-window -n editor
# Create window and run command
tmux new-window -t session:1 -n server "npm start"
# Create before current window
C-b : new-window -b -n name
Execution
Terminal window
tmux new-window -t development -n editor
Output
Terminal window
[new window created: editor]
  • C-b c is fastest way to create window
  • Windows appear as numbered tabs at bottom
  • Each window is independent shell environment

Navigate windows

Navigate between windows using keybindings or command line.

Code
Terminal window
# Go to next window
C-b n
# Go to previous window
C-b p
# Go to specific window by number (0-9)
C-b 0 # Go to window 0
C-b 1 # Go to window 1
# Go to last active window
C-b l
# List windows and select
C-b w
Execution
Terminal window
tmux select-window -t development:1
Output
Terminal window
[switched to window 1]
  • C-b n and p are essential for workflow
  • Number keys 0-9 jump directly to window
  • C-b l toggles between two most recent windows

Manage and Rename Windows

Rename, move, and organize windows

Rename and reorder windows

Rename windows for better organization and flexibility.

Code
Terminal window
# Rename current window (in tmux)
C-b ,
# Rename window via command
tmux rename-window -t session:0 newname
# Move window to different position
tmux move-window -t session:0 -s session:1
# Swap windows
tmux swap-window -t session:0 -s session:1
Execution
Terminal window
tmux rename-window -t development:0 editor
Output
Terminal window
[window renamed from 0 to editor]
  • C-b , is quick rename within tmux
  • Renaming is visual only, doesn't affect functionality
  • Useful for distinguishing similar windows

List and close windows

View window list, details, and close windows when no longer needed.

Code
Terminal window
# List windows in session
tmux list-windows -t session
# Get detailed window info
tmux display-message -t session -p "#{window_name}"
# Kill current window (in tmux)
C-b &
# Kill specific window
tmux kill-window -t session:0
Execution
Terminal window
tmux list-windows -t development
Output
Terminal window
0: editor* (2 panes) [80x24]
1: server (1 pane) [80x24]
2: test (1 pane) [80x24]
  • C-b & kills current window with confirmation
  • Asterisk (*) indicates active window
  • Closing last window closes session

Window Selection and Monitoring

Select windows and monitor activity

Use window list and selection menu

Interactively select windows or monitor them for activity.

Code
Terminal window
# Show window list menu (in tmux)
C-b w
# Choose window interactively
tmux choose-window
# Monitor window for activity
tmux set-window-option -t session:0 monitor-activity on
# Show window activity in status bar
tmux set-window-option -t session monitor-silence 30
Execution
Terminal window
tmux choose-window
Output
Terminal window
(0) editor
(1) server*
(2) test
  • C-b w shows window list with arrow navigation
  • Space or Enter selects window
  • Monitor activity useful for long-running processes

Panes

Split and manage panes within windows

Split Panes Vertically and Horizontally

Create pane layouts and split orientations

Split panes vertically and horizontally

Create side-by-side (vertical) or stacked (horizontal) pane layouts.

Code
Terminal window
# Split current pane vertically (left-right)
C-b %
# Split current pane horizontally (top-bottom)
C-b "
# Split vertically with command
tmux split-window -h -t session:0 "top"
# Split horizontally with specific size
tmux split-window -v -t session:0 -l 10
Execution
Terminal window
tmux split-window -h
Output
Terminal window
[pane 0 and 1 created]
  • C-b % for vertical split (new pane on right)
  • C-b " for horizontal split (new pane below)
  • Splits are always of current pane

Create complex pane layouts

Use preset layouts or create complex splits through scripting.

Code
Terminal window
# Display preset layouts
C-b Space # Cycle through layouts
# Pre-defined layouts
# even-horizontal, even-vertical, main-horizontal
# main-vertical, tiled
tmux select-layout -t session:0 main-horizontal
# Create custom split script
tmux new-window -t session \
&& tmux split-window -h \
&& tmux split-window -v -p 25
Execution
Terminal window
tmux select-layout even-horizontal
Output
Terminal window
[layout changed to even-horizontal]
  • C-b Space cycles through available layouts
  • Layouts auto-arrange panes
  • Great for consistent setups

Navigate and Resize Panes

Move focus between panes and resize them

Navigate between panes

Navigate between panes using vim-like keybindings or direct selection.

Code
Terminal window
# Move to pane in direction (vim-like navigation)
C-b h # Move left
C-b j # Move down
C-b k # Move up
C-b l # Move right
# Cycle through panes
C-b o # Go to next pane
C-b ; # Go to previously active pane
# Select pane by number
C-b q # Show pane numbers then press number
Execution
Terminal window
tmux select-pane -t session:0.1
Output
Terminal window
[focused on pane 1]
  • Requires vim-style navigation setup
  • Default keys might be different without config
  • C-b q shows pane numbers for direct access

Resize panes

Adjust pane sizes to focus on important areas.

Code
Terminal window
# Resize pane in direction (uppercase HJKL)
C-b H # Resize left
C-b J # Resize down
C-b K # Resize up
C-b L # Resize right
# Resize with command line
tmux resize-pane -t session:0.0 -U 5 # Up 5 lines
tmux resize-pane -t session:0.0 -R 10 # Right 10 cols
# Make equal size
C-b = # Distribute panes evenly
Execution
Terminal window
tmux resize-pane -t development:0.0 -U 10
Output
Terminal window
[pane resized]
  • Requires vim-style bindings setup
  • C-b = distributes space evenly
  • Useful for comparing output side-by-side

Close and Manage Panes

Remove, move, and organize panes

Close and remove panes

Remove panes or reorganize them across windows.

Code
Terminal window
# Close current pane (in tmux)
C-b x # Kill pane with confirmation
# Kill pane via command
tmux kill-pane -t session:0.0
# Break pane into new window
C-b !
# Join pane from another window
tmux join-pane -s session:0.0 -t session:1
Execution
Terminal window
tmux kill-pane -t development:0.1
Output
Terminal window
[pane 1 closed]
  • C-b x offers confirmation before killing
  • Breaking pane creates new window from it
  • Joining pane combines windows

Swap and manage pane layout

Reorganize pane positions within a window layout.

Code
Terminal window
# Swap current pane with next
C-b { # Move pane left
C-b } # Move pane right
# Swap specific panes
tmux swap-pane -t session:0.0 -s session:0.1
# Show pane layout
tmux display-message -t session:0 -p "#{window_layout}"
Execution
Terminal window
tmux swap-pane -t development:0.0 -s development:0.1
Output
Terminal window
[panes swapped]
  • C-b { and } change pane order visually
  • Useful for reordering without closing

Copy/Paste & Scrolling

Manage text copying, pasting, and buffer navigation

Enter Scroll Mode and Navigate Buffer

Access and scroll through text history

Enter scroll mode and navigate

Enter scroll mode to view terminal history and select text.

Code
Terminal window
# Enter scroll/copy mode (in tmux)
C-b [
# Navigate while in scroll mode
Arrow keys # Move up/down/left/right
Page Up/Page Down # Scroll by page
Home/End # Jump to start/end
g/G # Jump to beginning/end
# Exit scroll mode
q # Quit scroll mode
Execution
Terminal window
tmux send-keys -t session 'C-b' '['
Output
Terminal window
[scroll mode activated - use arrows to navigate]
  • C-b [ enters scroll/copy mode for viewing history
  • Once in mode, use vi keys (hjkl) or arrows to navigate
  • ESC or q exits without copying

Enable mouse support for scrolling

Enable mouse support for modern terminal interaction and scrolling.

Code
Terminal window
# Enable mouse support in tmux.conf
set -g mouse on
# With mouse enabled:
Scroll wheel # Scroll up/down
Click and drag # Select text (auto-copies)
Middle click # Paste selected
Right click # Show context menu
# Disable mouse for specific session
tmux set -t session mouse off
Execution
Terminal window
tmux set -g mouse on
Output
Terminal window
mouse on
  • Mouse mode makes tmux more intuitive for newcomers
  • Can toggle per session or globally
  • Click-to-select is faster than keyboard

Copy and Paste Text

Select, copy, and paste text between panes

Copy text in scroll mode

Select text in scroll mode and copy for pasting elsewhere.

Code
Terminal window
# Enter scroll mode
C-b [
# Position cursor and start selection
Space # Start selection at cursor
# Move to end of text (vim navigation or arrows)
Move with h/j/k/l or arrows
# Copy selection
Enter # Copy and exit mode
# Paste copied text (in tmux)
C-b ]
Execution
Terminal window
echo 'Copy mode workflow'
Output
Terminal window
Copy mode workflow
  • Space starts selection, Enter copies and exits
  • Works across panes and windows
  • Copied text stays in tmux buffer

Paste and manage buffers

Store multiple copied items and paste from specific buffers.

Code
Terminal window
# Paste from buffer (in tmux)
C-b ]
# List all buffers
tmux list-buffers
# Show specific buffer
tmux show-buffer -b buffer-id
# Paste specific buffer
tmux paste-buffer -b buffer-id
# Clear all buffers
tmux delete-buffer -b buffer-id
Execution
Terminal window
tmux list-buffers
Output
Terminal window
0: 245 bytes
1: 128 bytes
2: 512 bytes
  • Tmux maintains buffer history
  • Most recent copy is buffer 0
  • Useful for pasting multiple items without re-copying

Search in Buffer History

Find text within terminal history

Search within scroll buffer

Find specific text within terminal output history.

Code
Terminal window
# Enter scroll mode first
C-b [
# Start forward search
C-s # Enter search mode, type pattern
# Start backward search
C-r # Search backwards
# Navigate search results
n # Go to next match
N # Go to previous match
# Exit search
Escape # Return to scroll mode
q # Quit scroll mode completely
Execution
Terminal window
echo 'Search mode: C-b [ then C-s for forward search'
Output
Terminal window
Search mode active
  • C-s for forward search, C-r for backward
  • n and N navigate between matches
  • Case-sensitive by default

Search across pane history

Export terminal history or adjust buffer size for longer history.

Code
Terminal window
# Capture entire pane history to file
tmux capture-pane -t session:0.0 -p > history.txt
# Capture with layout
tmux capture-pane -t session:0.0 -p -e > formatted.txt
# Clear history
tmux clear-history -t session:0.0
# Set history size
set -g history-limit 50000
Execution
Terminal window
tmux capture-pane -t development:0 -p | head -20
Output
Terminal window
[previous terminal output...]
[previous terminal output...]
[previous terminal output...]
  • Default history limit is 2000 lines
  • Increase for long-running sessions
  • -e flag preserves colors in captured output

Keybindings & Commands

Essential keybindings and command mode usage

Essential Keybindings Reference

Most frequently used keybindings for daily work

Core session and window keybindings

Quick reference for tmux's most productive keybindings.

Code
SESSION/ATTACH
C-b d Detach from session
C-b ( Previous session
C-b ) Next session
WINDOWS
C-b c New window
C-b n Next window
C-b p Previous window
C-b l Last active window
C-b w List windows
C-b , Rename window
C-b & Kill window
PANES
C-b % Split vertical
C-b " Split horizontal
C-b h/j/k/l Navigate (vim)
C-b HJKL Resize (vim)
C-b o Next pane
C-b x Kill pane
C-b Space Cycle layouts
C-b ! Break pane to window
C-b {/} Move pane left/right
Execution
Terminal window
tmux list-keys | grep -E 'bind-key.*C-b' | head -20
Output
Terminal window
bind-key -T prefix c new-window
bind-key -T prefix d detach-client
bind-key -T prefix % split-window -h
bind-key -T prefix " split-window -v
  • C-b is default prefix (press before each binding)
  • Vim keys (h/j/k/l) available with configuration
  • Numbers 0-9 navigate directly to windows

Copy/paste and utility keybindings

Keybindings for text manipulation and information displays.

Code
COPY/PASTE
C-b [ Enter scroll mode
C-b ] Paste buffer
Space Start selection
Enter Copy selection
C-s Search forward
C-r Search backward
DISPLAY/INFO
C-b ? List keybindings
C-b : Enter command mode
C-b t Display clock
C-b q Show pane numbers
C-b $ Rename session
Execution
Terminal window
tmux list-keys -T copy-mode | head -15
Output
Terminal window
send-keys -X copy-selection
send-keys -X scroll-up
send-keys -X search-forward
  • Some bindings only work in copy mode
  • [object Object]
  • t displays clock overlay (press any key to exit)

Command Mode and Advanced Usage

Enter command mode for powerful operations

Access and use command mode

Command mode allows advanced operations like sending keystrokes to panes.

Code
Terminal window
# Enter command mode (in tmux)
C-b :
# Examples of commands
send-keys -t session:0.0 "ls -la" Enter
set -g mouse on
bind-key custom-key send-keys "command" Enter
# Get help for command
help command-name
# Source configuration file
source ~/.tmux.conf
Execution
Terminal window
tmux send-keys -t development "pwd" Enter
Output
Terminal window
/home/user/projects
  • send-keys runs commands in specified pane
  • Enter key needed to execute commands sent
  • Useful for automation scripts

Bind custom keys and utilities

Customize keybindings and run complex commands through command mode.

Code
Terminal window
# List all custom bindings
tmux list-keys
# Unbind a key
tmux unbind-key name
# Bind custom command
tmux bind-key R "send-keys -t session:0 'reload' Enter"
# Run external command from tmux
C-b :run "external-command"
# Execute tmux session setup script
tmux source-file ~/.tmux/setup.sh
Execution
Terminal window
tmux list-commands | wc -l
Output
Terminal window
135
  • Hundreds of tmux commands available
  • Custom bindings go in tmux.conf
  • Scripts can automate session setup

Configuration & Customization

Customize tmux behavior and appearance

Tmux Configuration File Basics

Set up your tmux.conf for custom settings

Create and structure tmux.conf

Create ~/.tmux.conf to customize tmux behavior globally.

Code
~/.tmux.conf
# Set default terminal (24-bit color support)
set -g default-terminal "screen-256color"
set -ga terminal-overrides ",xterm-256color:RGB"
# Set default shell
set -g default-shell /bin/bash
# Set base index (0 or 1)
set -g base-index 0
setw -g pane-base-index 0
# Set history limit
set -g history-limit 10000
# Mouse support
set -g mouse on
Execution
Terminal window
cat ~/.tmux.conf | head -10
Output
Terminal window
set -g default-terminal "screen-256color"
set -ga terminal-overrides ",xterm-256color:RGB"
set -g mouse on
  • use 'set' for session options, 'setw' for window options
  • -g flag for global, -t for specific target
  • -a flag appends/adds to option
  • Loaded on tmux start

Reload and apply configuration

Apply configuration changes without restarting tmux server.

Code
Terminal window
# Reload configuration (in tmux)
C-b : source-file ~/.tmux.conf
# Or from shell
tmux source-file ~/.tmux.conf
# Check specific option
tmux show-options -g | grep history
# Show all options
tmux show-options -g
Execution
Terminal window
tmux source-file ~/.tmux.conf
Output
Terminal window
[configuration reloaded]
  • source-file is safe command to reload
  • Changes apply immediately to new panes/windows
  • Existing panes may need refresh

Customize Status Line

Configure the bottom-of-window status bar

Configure left and right status

Customize status bar to show useful information and improve aesthetics.

Code
Terminal window
# Simple status format
set -g status-left "[#S]"
set -g status-right "#H | %a %d %b %H:%M"
# Complex left status with colors
set -g status-left "#[bg=blue,fg=white] #S #[default]"
# Add window list in middle
set -g status-justify centre
# Window status formatting
setw -g window-status-format "#[fg=white] #I: #W "
setw -g window-status-current-format "#[bg=green,fg=black] #I: #W #[default]"
Execution
Terminal window
tmux show-options -g | grep status
Output
Terminal window
status on
status-bg default
status-justify left
status-left [#S]
status-right #H | %a %d %b %H:%M
  • [object Object]

Colors and Styling

Apply colors and text attributes to UI elements

Apply colors and attributes

Apply color schemes to tmux UI components and text.

Code
Terminal window
# Standard colors
set -g status-bg black
set -g status-fg white
# Named colors for window
setw -g window-status-current-bg green
setw -g window-status-current-fg black
# 256 color palette
setw -g window-status-bg colour234 # Dark gray
setw -g window-status-fg colour248 # Light gray
# RGB hex colors (if supported)
setw -g pane-border-lines heavy
setw -g pane-border-style "fg=#444444"
Execution
Terminal window
tmux show-options -g status-bg
Output
Terminal window
status-bg black
  • [object Object]
  • [object Object]
  • [object Object]

Apply text attributes and combinations

Combine colors with text attributes for professional appearance.

Code
Terminal window
# Text attributes
#[bold] Bold text
#[underscore] Underlined
#[italics] Italics (if terminal supports)
#[dim] Dimmed text
#[fg=red] Red text
#[bg=yellow] Yellow background
#[default] Reset to defaults
# Combinations in status line
set -g status-left "#[fg=white,bg=blue,bold] #S #[default]"
setw -g window-status-current-format "#[fg=black,bg=green,bold] #W #[default]"
# For pane styling
setw -g pane-active-border-fg green
setw -g pane-border-fg colour240
Execution
Terminal window
echo 'Colors: black, red, green, yellow, blue, magenta, cyan, white'
Output
Terminal window
Colors list for terminal display
  • Always use
  • Test colors in your terminal first (256 vs true color)
  • Some attributes may not work in all terminals