---
title: "Tmux"
description: "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."
author: "Mohammad Abu Mattar"
canonical: https://mkabumattar.com/cheatsheets/tmux
---

# Tmux

Tmux is a powerful terminal multiplexer that allows you to manage multiple terminal sessions, windows, and panes within a single screen. This cheatsheet covers essential commands, keybindings, and configuration options for effective tmux usage.

## Quick Start

Start your first tmux session with a single command:

```bash
tmux new -s development
```

Then detach with `C-b d` and reattach from anywhere with:

```bash
tmux attach -t development
```

## Key Concepts

**Sessions**: Independent workspaces that continue running even if you disconnect. Useful for keeping servers and processes running.

**Windows**: Tabs within a session. Each window is a full terminal with its own working directory and history.

**Panes**: Splits within a window. Allows multiple shells side-by-side without opening new windows.

## Essential Keybindings

All keybindings use the prefix key `C-b` (Ctrl+B) unless configured otherwise:

- `C-b c` - Create new window
- `C-b n` / `C-b p` - Next/previous window
- `C-b %` / `C-b "` - Split vertical/horizontal
- `C-b h/j/k/l` - Navigate panes (requires vim-style config)
- `C-b [` - Enter scroll/copy mode
- `C-b d` - Detach from session
- `C-b ?` - List all keybindings
- `C-b :` - Enter command mode

## Popular Configuration

For vim-style navigation and mouse support, add to `~/.tmux.conf`:

```bash
# Enable 256 color support
set -g default-terminal "screen-256color"
set -ga terminal-overrides ",xterm-256color:RGB"

# Enable mouse
set -g mouse on

# Use vim keys for navigation
setw -g mode-keys vi
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

# Resize panes with vim keys
bind H resize-pane -L 5
bind J resize-pane -D 5
bind K resize-pane -U 5
bind L resize-pane -R 5

# Increase history limit
set -g history-limit 50000

# Reload config
bind r source-file ~/.tmux.conf
```

Then reload with `C-b :` and type `source-file ~/.tmux.conf`.

## Tips for Productivity

1. **Use Named Sessions**: `tmux new -s work` is easier to remember than session numbers
2. **Create Window Groups**: Organize windows logically within sessions (editor, server, testing)
3. **Pair Programming**: Multiple users can attach to the same session for collaboration
4. **Automation**: Use `tmux send-keys` in scripts to automate setup and testing
5. **Mouse Support**: Enable `set -g mouse on` for modern terminal comfort with familiar scrolling

## Resources

- Official Tmux Manual: https://linux.die.net/man/1/tmux
- GitHub Repository: https://github.com/tmux/tmux
- Community Wiki: https://github.com/tmux/tmux/wiki

## Getting Started

Start using tmux and learn basic concepts

### Starting Tmux

Launch tmux and create your first session

**Keywords:** start, launch, tmux, new, session

#### Start tmux without session name

```bash
# Start a tmux session
tmux

# Start tmux with UTF8 support
tmux -u

# Start with specific socket
tmux -S ~/.tmux.socket
```

_exec_
```bash
tmux
```

_output_
```bash
[new session created]
```

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

- Useful for quick sessions you don't plan to keep
- Creates session with numeric identifier
- Can reattach with tmux attach

#### Create named session

```bash
# 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"
```

_exec_
```bash
tmux new -s development
```

_output_
```bash
[new session created - development]
```

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

- Named sessions are easier to manage than numbered
- -d flag starts session detached (background)
- Can start in specific directory with shell commands

**Best practices:**

- Use descriptive session names like 'work', 'dev', 'personal'
- Create sessions detached for automated workflows
- Use UTF8 flag if dealing with international characters

**Common errors:**

- **sessions already exist**: Use tmux attach to connect to existing session instead

### Basic Concepts

Understand tmux structure and terminology

**Keywords:** sessions, windows, panes, structure, hierarchy

#### Understanding session, window, and pane hierarchy

```text
Session (development)
├── Window 0 (editor)
│   ├── Pane 0 (active)
│   └── Pane 1
├── Window 1 (terminal)
│   └── Pane 0
└── Window 2 (build)
    ├── Pane 0
    ├── Pane 1
    └── Pane 2
```

_exec_
```bash
tmux list-sessions && tmux list-windows
```

_output_
```bash
development: 2 windows
0: editor- (2 panes)
1: terminal- (1 pane)
```

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

- Session contains multiple windows
- Window contains multiple panes
- Each pane is a separate terminal shell

#### Check tmux server status

```bash
# List all sessions
tmux ls

# Get detailed session info
tmux info

# Show version
tmux -V
```

_exec_
```bash
tmux ls
```

_output_
```bash
development: 2 windows (80x24)
work: 1 window (120x30)
```

View active sessions and tmux configuration details.

- Useful for checking what's running before attaching
- Shows terminal dimensions for each session

**Best practices:**

- Understand session/window/pane relationship
- Use sessions for different projects
- Use windows for different tasks within project
- Use panes for side-by-side related work

**Common errors:**

- **no server running**: Sessions don't exist yet; start a new one with tmux new

### Help and Command Mode

Access built-in help and run commands

**Keywords:** help, command, keybindings, reference

#### Access help and keybindings

```bash
# 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
```

_exec_
```bash
tmux list-keys | head -20
```

_output_
```bash
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
```

Access comprehensive help system and keybinding references within tmux.

- C-b is the default prefix key
- Command mode allows advanced operations
- [object Object]

#### Run commands and display help

```bash
# 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
```

_exec_
```bash
tmux show-options -g
```

_output_
```bash
aggressive-resize off
allow-same-window on
base-index 0
bell-action any
```

Display tmux configuration and useful information overlays.

- [object Object]
- [object Object]
- Exit overlays with any key or Escape

**Best practices:**

- Learn core keybindings first
- Use ? for quick reference during work
- Explore tmux man page for advanced features

**Common errors:**

- **unknown command**: Check keybinding with tmux list-keys

## Sessions

Work with tmux sessions for isolated workspaces

### Create and Attach Sessions

Create new sessions and attach to existing ones

**Keywords:** new, attach, session, create, connect

#### Create and attach to new session

```bash
# 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
```

_exec_
```bash
tmux new -s devwork
```

_output_
```bash
[new session created - devwork]
```

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

- 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

```bash
# 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
```

_exec_
```bash
tmux attach -t development
```

_output_
```bash
[attached to development session]
```

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

- Must use exact session name or number
- -r flag makes it read-only (no input)
- Default is most recently used session

**Best practices:**

- Create session for each major project
- Detach before closing terminal (C-b d)
- Use descriptive names for easy recall

**Common errors:**

- **session not found**: Use tmux ls to see available sessions

### Session Switching and Management

Switch between sessions and manage multiple sessions

**Keywords:** switch, list, rename, kill, detach

#### Switch between sessions

```bash
# 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
```

_exec_
```bash
tmux switch -t work
```

_output_
```bash
[switched to work session]
```

Quickly switch between different sessions from command line or interactively.

- C-b ( and ) cycle through open sessions
- Useful for toggling between two sessions

#### List and manage sessions

```bash
# 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 '!^'
```

_exec_
```bash
tmux ls
```

_output_
```bash
development: 3 windows
work: 2 windows
testing: 1 window (current)
```

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

- Sessions persist until explicitly killed or tmux server stops
- Renaming helps organize long-running sessions
- Kill-session useful for cleanup after pairing sessions

**Best practices:**

- Regularly list sessions to stay organized
- Rename sessions to reflect current state
- Kill unused sessions to reduce server memory

**Common errors:**

- **can't find session**: Verify session name exists with tmux ls

### Detach and Reattach

Detach from sessions and manage disconnections

**Keywords:** detach, connection, background, reattach

#### Detach from session

```bash
# 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
```

_exec_
```bash
tmux detach-client -t development
```

_output_
```bash
[detached from development]
```

Safely detach from session, keeping it running in background.

- 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

```bash
# 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
```

_exec_
```bash
tmux list-clients
```

_output_
```bash
/dev/pts/0: 0 (80 x 24) [UTF8]
/dev/pts/1: 1 (120 x 30) [UTF8]
```

View client connections and session metadata.

- Multiple clients can be attached to same session
- Useful for pair programming
- Different connections can have different window sizes

**Best practices:**

- Always detach instead of killing terminal
- Reattach from another terminal to recover work
- Use detach to switch between local and remote work

**Common errors:**

- **can't attach from multiple locations**: Sessions do attach from multiple clients by design, but resize may differ

## Windows

Manage multiple windows within a tmux session

### Create and Navigate Windows

Create new windows and move between them

**Keywords:** new-window, windows, c, n, p, navigate

#### Create new window

```bash
# 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
```

_exec_
```bash
tmux new-window -t development -n editor
```

_output_
```bash
[new window created: editor]
```

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

- C-b c is fastest way to create window
- Windows appear as numbered tabs at bottom
- Each window is independent shell environment

#### Navigate windows

```bash
# 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
```

_exec_
```bash
tmux select-window -t development:1
```

_output_
```bash
[switched to window 1]
```

Navigate between windows using keybindings or command line.

- 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

**Best practices:**

- Use descriptive window names
- Create windows for different tasks (editor, server, test)
- Use number keys for frequent windows

**Common errors:**

- **window doesn't exist**: Create window first with C-b c or use list-windows to check

### Manage and Rename Windows

Rename, move, and organize windows

**Keywords:** rename, move, swap, kill, window

#### Rename and reorder windows

```bash
# 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
```

_exec_
```bash
tmux rename-window -t development:0 editor
```

_output_
```bash
[window renamed from 0 to editor]
```

Rename windows for better organization and flexibility.

- C-b , is quick rename within tmux
- Renaming is visual only, doesn't affect functionality
- Useful for distinguishing similar windows

#### List and close windows

```bash
# 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
```

_exec_
```bash
tmux list-windows -t development
```

_output_
```bash
0: editor* (2 panes) [80x24]
1: server (1 pane) [80x24]
2: test (1 pane) [80x24]
```

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

- C-b & kills current window with confirmation
- Asterisk (*) indicates active window
- Closing last window closes session

**Best practices:**

- Keep window count manageable (5-7 windows)
- Rename windows to their purpose
- Close unused windows to reduce clutter

**Common errors:**

- **can't kill last window**: Create new window first before killing last one

### Window Selection and Monitoring

Select windows and monitor activity

**Keywords:** select, activity, monitor, list, status

#### Use window list and selection menu

```bash
# 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
```

_exec_
```bash
tmux choose-window
```

_output_
```bash
(0) editor
(1) server*
(2) test
```

Interactively select windows or monitor them for activity.

- C-b w shows window list with arrow navigation
- Space or Enter selects window
- Monitor activity useful for long-running processes

**Best practices:**

- Use window activity monitoring for servers
- Set meaningful window names to identify at a glance
- Monitor important windows during pairing sessions

**Common errors:**

- **activity monitoring not showing**: Enable with set-window-option monitor-activity on

## Panes

Split and manage panes within windows

### Split Panes Vertically and Horizontally

Create pane layouts and split orientations

**Keywords:** split, pane, vertical, horizontal, layout

#### Split panes vertically and horizontally

```bash
# 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
```

_exec_
```bash
tmux split-window -h
```

_output_
```bash
[pane 0 and 1 created]
```

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

- 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

```bash
# 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
```

_exec_
```bash
tmux select-layout even-horizontal
```

_output_
```bash
[layout changed to even-horizontal]
```

Use preset layouts or create complex splits through scripting.

- C-b Space cycles through available layouts
- Layouts auto-arrange panes
- Great for consistent setups

**Best practices:**

- Split for related tasks (editor + server output)
- Keep splits to 2-3 panes for readability
- Use layouts to organize complex window structures

**Common errors:**

- **panes too small**: Resize with C-b HJKL or adjust split percentage

### Navigate and Resize Panes

Move focus between panes and resize them

**Keywords:** navigate, move, resize, focus, h, j, k, l

#### Navigate between panes

```bash
# 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
```

_exec_
```bash
tmux select-pane -t session:0.1
```

_output_
```bash
[focused on pane 1]
```

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

- Requires vim-style navigation setup
- Default keys might be different without config
- C-b q shows pane numbers for direct access

#### Resize panes

```bash
# 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
```

_exec_
```bash
tmux resize-pane -t development:0.0 -U 10
```

_output_
```bash
[pane resized]
```

Adjust pane sizes to focus on important areas.

- Requires vim-style bindings setup
- C-b = distributes space evenly
- Useful for comparing output side-by-side

**Best practices:**

- Use vim navigation for consistency with editor
- Resize panes to focus on most important content
- Keep working pane visible and readable

**Common errors:**

- **h/j/k/l keys not working**: Configure vim-style bindings in tmux.conf

### Close and Manage Panes

Remove, move, and organize panes

**Keywords:** close, kill, break, join, swap, pane

#### Close and remove panes

```bash
# 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
```

_exec_
```bash
tmux kill-pane -t development:0.1
```

_output_
```bash
[pane 1 closed]
```

Remove panes or reorganize them across windows.

- C-b x offers confirmation before killing
- Breaking pane creates new window from it
- Joining pane combines windows

#### Swap and manage pane layout

```bash
# 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}"
```

_exec_
```bash
tmux swap-pane -t development:0.0 -s development:0.1
```

_output_
```bash
[panes swapped]
```

Reorganize pane positions within a window layout.

- C-b { and } change pane order visually
- Useful for reordering without closing

**Best practices:**

- Close panes instead of windows for minor changes
- Use break-pane to promote pane to window
- Keep pane count under 10 for manageability

**Common errors:**

- **can't close last pane**: Close window instead with C-b &

## Copy/Paste & Scrolling

Manage text copying, pasting, and buffer navigation

### Enter Scroll Mode and Navigate Buffer

Access and scroll through text history

**Keywords:** scroll, buffer, history, navigation, text

#### Enter scroll mode and navigate

```bash
# 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
```

_exec_
```bash
tmux send-keys -t session 'C-b' '['
```

_output_
```bash
[scroll mode activated - use arrows to navigate]
```

Enter scroll mode to view terminal history and select text.

- 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

```bash
# 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
```

_exec_
```bash
tmux set -g mouse on
```

_output_
```bash
mouse on
```

Enable mouse support for modern terminal interaction and scrolling.

- Mouse mode makes tmux more intuitive for newcomers
- Can toggle per session or globally
- Click-to-select is faster than keyboard

**Best practices:**

- Use mouse for quick text selection
- Learn keyboard navigation for scripting
- Combine both methods for efficiency

**Common errors:**

- **mouse selection not working**: Enable with 'set -g mouse on' in tmux.conf

### Copy and Paste Text

Select, copy, and paste text between panes

**Keywords:** copy, paste, selection, buffer, clipboard

#### Copy text in scroll mode

```bash
# 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 ]
```

_exec_
```bash
echo 'Copy mode workflow'
```

_output_
```bash
Copy mode workflow
```

Select text in scroll mode and copy for pasting elsewhere.

- Space starts selection, Enter copies and exits
- Works across panes and windows
- Copied text stays in tmux buffer

#### Paste and manage buffers

```bash
# 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
```

_exec_
```bash
tmux list-buffers
```

_output_
```bash
0: 245 bytes
1: 128 bytes
2: 512 bytes
```

Store multiple copied items and paste from specific buffers.

- Tmux maintains buffer history
- Most recent copy is buffer 0
- Useful for pasting multiple items without re-copying

**Best practices:**

- Use Space and Enter for quick copy-paste
- Check buffers if paste doesn't show expected text
- Clear old buffers to preserve memory

**Common errors:**

- **pasted wrong text**: Check buffer list with tmux list-buffers

### Search in Buffer History

Find text within terminal history

**Keywords:** search, find, buffer, history, pattern

#### Search within scroll buffer

```bash
# 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
```

_exec_
```bash
echo 'Search mode: C-b [ then C-s for forward search'
```

_output_
```bash
Search mode active
```

Find specific text within terminal output history.

- C-s for forward search, C-r for backward
- n and N navigate between matches
- Case-sensitive by default

#### Search across pane history

```bash
# 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
```

_exec_
```bash
tmux capture-pane -t development:0 -p | head -20
```

_output_
```bash
[previous terminal output...]
[previous terminal output...]
[previous terminal output...]
```

Export terminal history or adjust buffer size for longer history.

- Default history limit is 2000 lines
- Increase for long-running sessions
- -e flag preserves colors in captured output

**Best practices:**

- Increase history-limit for debugging long processes
- Use capture-pane to save output for analysis
- Build search patterns into workflow

**Common errors:**

- **search not finding text**: Make sure you're in scroll mode, then use C-s for search

## Keybindings & Commands

Essential keybindings and command mode usage

### Essential Keybindings Reference

Most frequently used keybindings for daily work

**Keywords:** keybindings, shortcuts, prefix, commands, c-b

#### Core session and window keybindings

```text
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
```

_exec_
```bash
tmux list-keys | grep -E 'bind-key.*C-b' | head -20
```

_output_
```bash
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
```

Quick reference for tmux's most productive keybindings.

- 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

```text
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
```

_exec_
```bash
tmux list-keys -T copy-mode | head -15
```

_output_
```bash
send-keys -X copy-selection
send-keys -X scroll-up
send-keys -X search-forward
```

Keybindings for text manipulation and information displays.

- Some bindings only work in copy mode
- [object Object]
- t displays clock overlay (press any key to exit)

**Best practices:**

- Memorize core ten keybindings for daily efficiency
- Use ? when you forget a keybinding
- Customize keybindings to match your editor

**Common errors:**

- **keybinding does nothing**: Make sure prefix (C-b) is shown in terminal or run tmux list-keys

### Command Mode and Advanced Usage

Enter command mode for powerful operations

**Keywords:** command, mode, advanced, send-keys, bind

#### Access and use command mode

```bash
# 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
```

_exec_
```bash
tmux send-keys -t development "pwd" Enter
```

_output_
```bash
/home/user/projects
```

Command mode allows advanced operations like sending keystrokes to panes.

- send-keys runs commands in specified pane
- Enter key needed to execute commands sent
- Useful for automation scripts

#### Bind custom keys and utilities

```bash
# 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
```

_exec_
```bash
tmux list-commands | wc -l
```

_output_
```bash
135
```

Customize keybindings and run complex commands through command mode.

- Hundreds of tmux commands available
- Custom bindings go in tmux.conf
- Scripts can automate session setup

**Best practices:**

- Learn basic keybindings before command mode
- Use command mode for one-off operations
- Move frequent commands to keybindings

**Common errors:**

- **unknown command**: Check command name with tmux list-commands

## Configuration & Customization

Customize tmux behavior and appearance

### Tmux Configuration File Basics

Set up your tmux.conf for custom settings

**Keywords:** config, configuration, tmux.conf, set, option

#### Create and structure tmux.conf

```bash
# Location: ~/.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
```

_exec_
```bash
cat ~/.tmux.conf | head -10
```

_output_
```bash
set -g default-terminal "screen-256color"
set -ga terminal-overrides ",xterm-256color:RGB"
set -g mouse on
```

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

- 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

```bash
# 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
```

_exec_
```bash
tmux source-file ~/.tmux.conf
```

_output_
```bash
[configuration reloaded]
```

Apply configuration changes without restarting tmux server.

- source-file is safe command to reload
- Changes apply immediately to new panes/windows
- Existing panes may need refresh

**Best practices:**

- Keep tmux.conf well-commented
- Test config changes in separate session first
- Use reload frequently during setup

**Common errors:**

- **bad format or unknown command**: Check syntax, use: tmux source-file to see errors

### Customize Status Line

Configure the bottom-of-window status bar

**Keywords:** status, statusline, bar, format, appearance

#### Configure left and right status

```bash
# 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]"
```

_exec_
```bash
tmux show-options -g | grep status
```

_output_
```bash
status on
status-bg default
status-justify left
status-left [#S]
status-right #H | %a %d %b %H:%M
```

Customize status bar to show useful information and improve aesthetics.

- null
- null
- null
- [object Object]

**Best practices:**

- Keep status line readable with minimal clutter
- Show essential info like host, session, time
- Use colors sparingly for focus

**Common errors:**

- **status showing wrong format**: Check syntax with tmux show-options -g

### Colors and Styling

Apply colors and text attributes to UI elements

**Keywords:** colors, attributes, styling, foreground, background

#### Apply colors and attributes

```bash
# 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"
```

_exec_
```bash
tmux show-options -g status-bg
```

_output_
```bash
status-bg black
```

Apply color schemes to tmux UI components and text.

- [object Object]
- [object Object]
- [object Object]

#### Apply text attributes and combinations

```bash
# 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
```

_exec_
```bash
echo 'Colors: black, red, green, yellow, blue, magenta, cyan, white'
```

_output_
```bash
Colors list for terminal display
```

Combine colors with text attributes for professional appearance.

- Always use
- Test colors in your terminal first (256 vs true color)
- Some attributes may not work in all terminals

**Best practices:**

- Use high contrast for readability
- Limit color palette to 3-4 main colors
- Test on different terminals

**Common errors:**

- **colors look wrong or washed out**: Check default-terminal setting, may need 256color or RGB support
