Tmux?

tmux is a terminal multiplexer that enables you to create, access, and control multiple terminal sessions from a single screen. Key advantages include:

  • Session Persistence: Detach from a session and re-attach later, preserving running processes even if your SSH connection drops.
  • Window & Pane Management: Divide your terminal into multiple windows (tabs) and panes (splits).
  • Scriptability: Automate terminal layouts and development environments.

Installation

Install tmux using your distribution’s native package manager:

Debian / Ubuntu / Linux Mint

1
2
sudo apt update
sudo apt install tmux -y

Fedora / RHEL / CentOS

1
2
3
4
5
6
7
8
# Fedora
sudo dnf install tmux -y

# RHEL / CentOS (8+)
sudo dnf install tmux -y

# Older RHEL/CentOS
sudo yum install tmux -y

Arch Linux / Manjaro

1
sudo pacman -S tmux

Basic Concepts & Usage Flow

A tmux hierarchy consists of three levels:

  1. Server / Session: A collection of windows managed by the background daemon.
  2. Window: A single screen within a session (like a browser tab).
  3. Pane: A subdivided section within a window (vertical or horizontal split).
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
+-------------------------------------------------------------+
| Session: "dev"                                              |
| +-------------------------+ +-----------------------------+ |
| | Window 0: "editor"      | | Window 1: "logs"            | |
| | +-----------+---------+ | | +-------------------------+ | |
| | | Pane 0    | Pane 1  | | | | Pane 0                  | | |
| | | (nvim)    | (htop)  | | | | (tail -f server.log)    | | |
| | +-----------+---------+ | | +-------------------------+ | |
| +-------------------------+ +-----------------------------+ |
+-------------------------------------------------------------+

Command Line Workflow

ActionCommand
Start a new unnamed sessiontmux
Start a named sessiontmux new -s <session-name>
List active sessionstmux ls
Attach to last sessiontmux a or tmux attach
Attach to named sessiontmux a -t <session-name>
Detach from current sessionPress Ctrl+b then d
Kill a specific sessiontmux kill-session -t <session-name>
Kill all tmux sessionstmux kill-server

Default Hotkeys Quick Reference

All tmux default shortcuts start with the Prefix key: Ctrl+b (written as Prefix).

Session Control

  • Prefix d : Detach from current session.
  • Prefix s : Interactively select/switch session.
  • Prefix $ : Rename current session.
  • Prefix ( / ) : Switch to previous / next session.

Window Management

  • Prefix c : Create a new window.
  • Prefix , : Rename current window.
  • Prefix w : List and select windows/sessions interactively.
  • Prefix n : Go to next window.
  • Prefix p : Go to previous window.
  • Prefix 0..9 : Switch to window by index number.
  • Prefix & : Kill current window.

Pane Management

  • Prefix % : Split pane vertically (left | right).
  • Prefix " : Split pane horizontally (top / bottom).
  • Prefix o : Swap/cycle focus to the next pane.
  • Prefix Arrow Keys : Move focus to adjacent pane (Up/Down/Left/Right).
  • Prefix z : Toggle zoom on focused pane (full screen toggle).
  • Prefix x : Kill current pane.
  • Prefix { / } : Swap current pane with previous / next pane.
  • Prefix Space : Cycle through preset pane layouts.
  • Prefix Ctrl+Arrow : Resize current pane in 1-cell increments.

Copy / Scroll Mode

  • Prefix [ : Enter Copy / Scroll mode.

  • Use Arrow keys or Page Up/Down to navigate buffer.

  • Press Space to start text selection.

  • Press Enter to copy selection to buffer and exit copy mode.

  • Prefix ] : Paste text from tmux copy buffer.

  • Prefix # : View all buffer history.

Customization (~/.tmux.conf)

Create or edit ~/.tmux.conf to configure your tmux preferences.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# -----------------------------------------------------------------------------
# General Settings
# -----------------------------------------------------------------------------
# Change prefix from Ctrl+b to Ctrl+a (easier to reach)
unbind C-b
set -g prefix C-a
bind C-a send-prefix

# Start window and pane numbering at 1 instead of 0
set -g base-index 1
setw -g pane-base-index 1

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

# Enable mouse support (clickable windows, panes, resizable borders)
set -g mouse on

# Increase scrollback buffer size (default is 2000 lines)
set -g history-limit 10000

# Faster command sequences (removes delay after ESC)
set -s escape-time 10

# -----------------------------------------------------------------------------
# Key Bindings
# -----------------------------------------------------------------------------
# Reload configuration file with 'Prefix r'
bind r source-file ~/.tmux.conf \; display-message "tmux config reloaded!"

# Intuitive pane splitting (opens in current working directory)
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current-path}"

# Vim-style pane navigation
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

# -----------------------------------------------------------------------------
# Visual Styling & Status Line
# -----------------------------------------------------------------------------
# Enable 256 color terminal support
set -g default-terminal "screen-256color"

# Status bar aesthetic
set -g status-style bg=#1e1e2e,fg=#cdd6f4
set -g status-left "#[fg=#89b4fa,bold] [#S] "
set -g status-right "#[fg=#a6e3a1]%Y-%m-%d %H:%M "
set -g window-status-current-style bg=#89b4fa,fg=#11111b,bold