tmux vs screen — Complete Comparison & tmux Deep Dive

tmux vs screen — Complete Comparison & tmux Deep Dive

What is a Terminal Multiplexer?

A terminal multiplexer lets you manage multiple terminal sessions within a single window. It allows you to:

  • Keep programs running in the background even after closing your terminal
  • Split a terminal window into multiple panes
  • Detach and reattach to sessions seamlessly
  • Share a session with other users for pair programming

The two most popular choices are GNU Screen and tmux.

A Brief History

Screen was released in 1987 as part of the GNU project — the grandparent of terminal multiplexers. It ships pre-installed on virtually every Linux distribution.

tmux was created in 2007 by Nicholas Marriott (an OpenBSD developer). Screen’s codebase had grown stale and hard to maintain; tmux was designed from scratch with a cleaner, more modern architecture and BSD licensing.

Screen vs tmux: Feature Comparison

Feature Screen tmux
First release 1987 2007
Config file ~/.screenrc ~/.tmux.conf
Default prefix Ctrl+a Ctrl+b
Vertical split Patch required Native
Horizontal split Native Native
Status bar Off by default, needs config Built-in, feature-rich
256 colors Requires screen-256color Default
True color No Yes
Copy mode vi/emacs vi/emacs
Scripting Limited Flexible (send-keys, etc.)
Plugin ecosystem Minimal TPM, tmux-resurrect, etc.
Session persistence None tmux-resurrect plugin
Buffer management Basic Advanced
Cross-platform Almost everywhere Almost everywhere
License GPL BSD

Bottom line: For basic detach/attach in a single window, both are fine. For splits, customization, and scripting, tmux is the clear winner.

Installing tmux

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# macOS
brew install tmux

# Ubuntu/Debian
sudo apt install tmux

# CentOS/RHEL/Fedora
sudo dnf install tmux

# Arch Linux
sudo pacman -S tmux

# From source
git clone https://github.com/tmux/tmux.git
cd tmux
sh autogen.sh
./configure && make && sudo make install

Verify:

1
tmux -V   # e.g. tmux 3.5

Core Concepts

tmux has a three-tier architecture:

1
2
3
4
tmux
├── Session ← top-level, represents a "project"
│ └── Window ← like a "tab" in your terminal
│ └── Pane ← a split region within a window

Session: An independent workspace. You can have multiple sessions, each with its own set of windows.

Window: Like a tab — fills the entire terminal.

Pane: A split region within a window. Panes can be tiled horizontally, vertically, or in complex layouts.

All interactive commands start with the Prefix Key (default Ctrl+b).

Session Management

Command-line

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Create and attach
tmux new -s mysession

# Create without attaching
tmux new -s mysession -d

# List sessions
tmux ls

# Attach to existing
tmux attach -t mysession

# Rename
tmux rename-session -t mysession newsession

# Kill
tmux kill-session -t mysession

# Kill everything
tmux kill-server

Key Bindings (inside tmux)

Keys Action
Prefix d Detach from session
Prefix s Interactive session picker
Prefix $ Rename current session
Prefix ( Switch to previous session
Prefix ) Switch to next session
Prefix L Switch to last session

Window Management

Keys Action
Prefix c Create new window
Prefix , Rename current window
Prefix w Interactive window picker
Prefix p Previous window
Prefix n Next window
Prefix 0–9 Go to Nth window
Prefix l Go to last active window
Prefix & Close current window
Prefix . Move current window (prompt for index)
Prefix f Search window by title

Pane Management

This is where tmux truly shines over Screen.

Creating Panes

Keys Action
Prefix % Split vertically (left/right)
Prefix " Split horizontally (top/bottom)
Keys Action
Prefix o Cycle to next pane
Prefix ↑/↓/←/→ Move to pane in direction
Prefix ; Toggle to last active pane
Prefix q Show pane numbers, press one to jump
Prefix { Swap pane left
Prefix } Swap pane right

Resizing

Keys Action
Prefix Ctrl+↑/↓/←/→ Resize by 1 cell
Prefix Alt+↑/↓/←/→ Resize by 5 cells
Prefix z Zoom pane in/out (fullscreen toggle)
Prefix space Cycle through layouts

Other Pane Operations

Keys Action
Prefix x Kill current pane
Prefix ! Break pane into a new window
Prefix Ctrl+o Rotate all panes forward
Prefix Alt+o Rotate all panes backward

Synchronized Input

Send the same keystrokes to every pane at once:

1
2
Prefix : setw synchronize-panes on    # enable
Prefix : setw synchronize-panes off # disable

Copy Mode

1
Prefix [    # enter copy mode

Navigate with vi or emacs keys (default: emacs, switch with setw -g mode-keys vi):

vi emacs Action
h/j/k/l C-b/C-n/C-p/C-f Move cursor
w/b M-f/M-b Word jump
Ctrl-u/Ctrl-d Ctrl-u/Ctrl-d Half-page scroll
gg/G M-< / M-> Start/end of buffer
v Ctrl-space Begin selection
y Ctrl-w Yank (copy)
q Escape Exit copy mode

Paste: Prefix ]

Configuring tmux (~/.tmux.conf)

tmux reads configuration from ~/.tmux.conf (or ~/.config/tmux/tmux.conf).

Here’s a production-ready configuration:

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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# ==================== Base Settings ====================

# Use Ctrl+a as prefix (matches Screen, easier to reach)
set -g prefix C-a
unbind C-b
bind C-a send-prefix

# Terminal
set -g default-terminal "tmux-256color"
set -ga terminal-overrides ",*256col*:Tc"

# Mouse support
set -g mouse on

# Decrease escape delay for faster response
set -g escape-time 10

# Increase scrollback buffer
set -g history-limit 50000

# vi-style key table
set-window-option -g mode-keys vi
set -g status-keys vi

# Start indexing at 1
set -g base-index 1
setw -g pane-base-index 1

# Auto-renumber windows
set -g renumber-windows on

# Disable automatic window rename
setw -g automatic-rename off
set-option -g allow-rename off

# ==================== Key Bindings ====================

# Visual split keys
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"

# Reload config
bind r source-file ~/.tmux.conf \; display-message "Config reloaded!"

# Vim-style pane switching (Ctrl+hjkl)
bind -n C-h select-pane -L
bind -n C-j select-pane -D
bind -n C-k select-pane -U
bind -n C-l select-pane -R

# Shift+arrow keys to resize
bind -n S-Left resize-pane -L 5
bind -n S-Right resize-pane -R 5
bind -n S-Up resize-pane -U 5
bind -n S-Down resize-pane -D 5

# Quick window switching (Alt+number)
bind-key -n M-1 select-window -t 1
bind-key -n M-2 select-window -t 2
bind-key -n M-3 select-window -t 3
bind-key -n M-4 select-window -t 4
bind-key -n M-5 select-window -t 5

# ==================== Status Bar ====================

set -g status-position top
set -g status-interval 5
set -g status-style bg=black,fg=white

set -g status-left "#[fg=black,bg=green] #S "
set -g status-left-style fg=green,bold

setw -g window-status-format " #I:#W "
setw -g window-status-current-format "#[fg=white,bg=blue] #I:#W "
setw -g window-status-current-style bg=blue,fg=white
setw -g window-status-separator " "

set -g status-right "#[fg=white,bg=black] %Y-%m-%d %H:%M "
set -g status-right-style fg=white,bg=black

setw -g monitor-activity on
set -g visual-activity on

# ==================== Pane Borders ====================

set -g pane-border-style fg=brightblack
set -g pane-active-border-style fg=cyan

set -g set-titles on
set -g set-titles-string "#T"

# ==================== Misc ====================

set -g focus-events on
set -g bell-action none

bind c new-window -c "#{pane_current_path}"
bind % split-window -h -c "#{pane_current_path}"
bind '"' split-window -v -c "#{pane_current_path}"

Reload after editing:

1
2
tmux source-file ~/.tmux.conf
# or from inside tmux: Prefix + r

Advanced Techniques

1. tmux-resurrect + tmux-continuum: Session Persistence

These plugins let you save and restore tmux sessions across reboots.

1
2
# Install TPM (Tmux Plugin Manager)
git clone https://github.com/tmux-plugins/tpm ~/.config/tmux/plugins/tpm

Add to ~/.tmux.conf:

1
2
3
4
5
6
7
8
9
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'

set -g @resurrect-capture-pane-contents 'on'
set -g @continuum-restore 'on'
set -g @resurrect-strategy-vim 'session'

run '~/.config/tmux/plugins/tpm/tpm'

Install plugins: Prefix + I (capital I).

Usage:

  • Prefix Ctrl+s — save manually
  • Prefix Ctrl+r — restore
  • tmux-continuum auto-saves every 15 minutes

2. Pair Programming

Multiple users can attach to the same tmux session simultaneously.

1
2
3
4
5
# User A creates the session
tmux new -s pair-session

# User B attaches (same machine or via SSH)
tmux attach -t pair-session

3. Vim/Neovim Integration

Use the same Ctrl+hjkl bindings to navigate both tmux panes and Vim windows:

In ~/.tmux.conf:

1
2
3
4
bind -n C-h select-pane -L
bind -n C-j select-pane -D
bind -n C-k select-pane -U
bind -n C-l select-pane -R

In ~/.vimrc:

1
2
3
4
5
6
7
8
9
tnoremap <C-h> <C-\><C-n><C-w>h
tnoremap <C-j> <C-\><C-n><C-w>j
tnoremap <C-k> <C-\><C-n><C-w>k
tnoremap <C-l> <C-\><C-n><C-w>l

nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l

4. Scripted Workspace Setup

Automate your development environment:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/bash
# dev-session.sh — one-command dev environment

session="dev"

tmux new-session -d -s $session

# Window 1: editor
tmux rename-window -t $session:1 'editor'
tmux send-keys -t $session:1 'vim' Enter

# Window 2: terminal with 3 panes
tmux new-window -t $session -n 'terminal'
tmux split-window -h -t $session:2
tmux split-window -v -t $session:2.1
tmux send-keys -t $session:2.1 'npm run dev' Enter
tmux send-keys -t $session:2.2 'git status' Enter
tmux send-keys -t $session:2.3 'htop' Enter

# Window 3: logs
tmux new-window -t $session -n 'logs'
tmux send-keys -t $session:3 'tail -f /var/log/nginx/access.log' Enter

tmux attach -t $session

5. Quick inline command pane

1
2
3
4
5
6
# Open a temporary pane and close after command runs
Prefix :
# Type: run-shell "some-command"

# Or bind a key:
bind-key -n M-x command-prompt -p "Run:" "run-shell \"%%\""

6. Buffer Management

1
2
3
4
Prefix : list-buffers   # list all paste buffers
Prefix : choose-buffer # interactive picker
Prefix = # same as above
Prefix # # list paste history

7. Nested tmux

When running tmux inside tmux (e.g., SSH into a remote server that also uses tmux):

1
2
# Double-tap prefix to send one prefix to inner session
bind C-a send-prefix

8. Session Info at a Glance

1
tmux list-sessions -F "#S: #{session_windows} windows [#{session_width}x#{session_height}] (#{session_created_string})"

FAQ

Q: True color support

1
2
3
# In ~/.tmux.conf:
set -g default-terminal "tmux-256color"
set -ga terminal-overrides ",*256col*:Tc"

Verify with:

1
curl -s https://gist.githubusercontent.com/lifepillar/09a44b8cf0f9397465614e622979107f/raw/24-bit-color.sh | bash

Q: Auto-attach to last session on terminal open?

1
2
3
4
# In ~/.zshrc or ~/.bashrc
if [[ -z "$TMUX" && -n "$(tmux list-sessions 2>/dev/null)" ]]; then
tmux attach-session -t "$(tmux list-sessions -F '#{session_name}' | fzf)"
fi

Q: How to open new panes/windows in the current directory?

Use the -c "#{pane_current_path}" flag in your bindings (already included in the config above).

Conclusion

Use Case Recommendation
Stable remote session persistence Both work; Screen is sufficient
Split panes, multi-window workflows tmux
Long-running headless server tasks Screen (lighter)
Vim-style pane navigation tmux
Session save/restore across reboots tmux + tmux-resurrect
Legacy systems Screen (pre-installed)
Modern config & plugin ecosystem tmux

If you’re new to terminal multiplexers, start with tmux. Its learning curve is slightly steeper than Screen, but the content in this guide covers everything you need — from first launch to daily mastery. Spend an hour tuning your .tmux.conf, and every workday after will feel noticeably more efficient.

中文/EN