If you SSH into servers, run long processes, or just want a better terminal experience, tmux changes everything. Sessions persist through disconnects, panes let you see multiple things at once, and once you build muscle memory, you’ll wonder how you worked without it.
Why tmux?# Sessions survive disconnects - SSH drops, laptop sleeps, terminal crashes? Your work continues.Split panes - Editor on the left, tests on the right, logs at the bottom.Multiple windows - Like browser tabs for your terminal.Pair programming - Share a session with someone else in real-time.Scriptable - Automate your development environment setup.Getting Started# 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Start new session
tmux
# Start named session
tmux new -s myproject
# Detach (inside tmux)
Ctrl+b d
# List sessions
tmux ls
# Attach to session
tmux attach -t myproject
# Kill session
tmux kill-session -t myproject
The key prefix is Ctrl+b by default. Press it, release, then press the next key.
Essential Keybindings# Sessions# Key Action Ctrl+b dDetach Ctrl+b sList sessions Ctrl+b $Rename session
Windows (Tabs)# Key Action Ctrl+b cCreate window Ctrl+b ,Rename window Ctrl+b nNext window Ctrl+b pPrevious window Ctrl+b 0-9Go to window N Ctrl+b &Kill window
Panes (Splits)# Key Action Ctrl+b %Split vertical Ctrl+b "Split horizontal Ctrl+b arrowMove between panes Ctrl+b xKill pane Ctrl+b zToggle pane zoom Ctrl+b {Move pane left Ctrl+b }Move pane right Ctrl+b SpaceCycle layouts
Copy Mode# Key Action Ctrl+b [Enter copy mode qExit copy mode SpaceStart selection EnterCopy selection Ctrl+b ]Paste
Practical Configuration# Create ~/.tmux.conf:
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
# Better prefix (Ctrl+a instead of Ctrl+b)
unbind C-b
set -g prefix C-a
bind C-a send-prefix
# Start windows and panes at 1, not 0
set -g base-index 1
setw -g pane-base-index 1
# Easy reload
bind r source-file ~/.tmux.conf \; display "Reloaded!"
# Intuitive splits (| and -)
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
# Navigate panes with vim keys
bind h select -pane -L
bind j select -pane -D
bind k select -pane -U
bind l select -pane -R
# Resize panes
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5
# Mouse support
set -g mouse on
# Don't rename windows automatically
set -g allow-rename off
# Increase scrollback
set -g history-limit 50000
# Faster escape (for vim)
set -sg escape-time 0
# 256 colors
set -g default-terminal "screen-256color"
# Status bar
set -g status-style bg = black,fg= white
set -g status-left "[#S] "
set -g status-right "%H:%M %d-%b"
Reload with tmux source ~/.tmux.conf or the r binding above.
Common Workflows# Development Layout# 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
#!/bin/bash
# dev-session.sh
SESSION = "dev"
tmux new-session -d -s $SESSION -c ~/project
# Main window: editor + terminal
tmux rename-window -t $SESSION :1 'code'
tmux send-keys -t $SESSION :1 'nvim .' C-m
tmux split-window -h -t $SESSION :1 -c ~/project
tmux resize-pane -t $SESSION :1 -x 40%
# Second window: servers
tmux new-window -t $SESSION -n 'servers' -c ~/project
tmux send-keys -t $SESSION :2 'npm run dev' C-m
tmux split-window -v -t $SESSION :2 -c ~/project
tmux send-keys -t $SESSION :2 'docker-compose logs -f' C-m
# Third window: git/misc
tmux new-window -t $SESSION -n 'git' -c ~/project
# Select first window
tmux select -window -t $SESSION :1
tmux attach -t $SESSION
SSH Jump + Persistent Work# 1
2
3
4
5
6
7
8
9
10
11
12
13
# On remote server
tmux new -s work
# Work on your project...
# Disconnect (close laptop, go home)
Ctrl+b d
# Later, reconnect
ssh server
tmux attach -t work
# Everything is exactly as you left it
Monitoring Dashboard# 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/bash
# monitor.sh
tmux new-session -d -s monitor
# Pane 1: htop
tmux send-keys 'htop' C-m
# Pane 2: logs
tmux split-window -h
tmux send-keys 'tail -f /var/log/syslog' C-m
# Pane 3: network
tmux split-window -v
tmux send-keys 'watch -n 1 "netstat -tuln | head -20"' C-m
# Pane 4: disk
tmux select -pane -t 0
tmux split-window -v
tmux send-keys 'watch -n 5 df -h' C-m
tmux attach -t monitor
Session Management# tmuxinator# For complex session setups, use tmuxinator:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# ~/.tmuxinator/project.yml
name : project
root : ~/code/myproject
windows :
- editor :
layout : main-vertical
panes :
- nvim
- # empty shell
- servers :
layout : even-horizontal
panes :
- npm run dev
- docker-compose up
- git :
- git status
1
tmuxinator start project
Session Restoration# Install tmux-resurrect for session persistence across reboots:
1
2
3
4
5
6
# In ~/.tmux.conf
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-resurrect'
# Press prefix + Ctrl+s to save
# Press prefix + Ctrl+r to restore
Advanced Tips# Send Commands to Panes# 1
2
3
4
5
6
7
# Send to specific pane
tmux send-keys -t mysession:1.0 'npm test' C-m
# Broadcast to all panes
Ctrl+b :setw synchronize-panes on
# Type commands (goes to all panes)
Ctrl+b :setw synchronize-panes off
Capture Pane Output# 1
2
3
4
5
6
7
8
# Capture visible content
tmux capture-pane -p > output.txt
# Capture with history
tmux capture-pane -p -S -1000 > output.txt
# Capture from specific pane
tmux capture-pane -t mysession:1.0 -p
Pipe Pane to File# 1
2
3
4
5
# Log all output to file
tmux pipe-pane -t mysession:1.0 'cat >> ~/pane.log'
# Stop logging
tmux pipe-pane -t mysession:1.0
Nested tmux (SSH into tmux inside tmux)# 1
2
3
4
5
6
# Double prefix to send to inner tmux
Ctrl+b Ctrl+b <command>
# Or use different prefix for inner
# On remote server's ~/.tmux.conf:
set -g prefix C-s
Troubleshooting# “sessions should be nested” warning# 1
2
# Force attach even if already in tmux
tmux attach -t session || tmux new -s session
Terminal colors wrong# 1
2
3
# In ~/.tmux.conf
set -g default-terminal "tmux-256color"
set -ga terminal-overrides ",*256col*:Tc"
1
2
# Enable mouse mode
set -g mouse on
Cheat Sheet# # t t t t # d c , n % " x z [ m m m m / S u u u u I p e x x x x n s s s n l a k i i e s t i d D N R N S S K Z C o w t l e e e e e p p i o o n a l t w n x l l l o p s - c - t a a t i i l m y s h s m c w m / t t e u h i e p p p m n - s x n r v h a a o a t s d w e e o n n d m i ( o i v r r e e e e n o a w n t i a n f d w i z m t o i c o e - e w n a n t r d l t o a n C w l a t C L A m r r i t e l e s t + a t a b t c ) e s h e s s e s s i s o i n o s n
tmux transforms the terminal from a single workspace into a persistent, multi-pane environment. The learning curve is real—you’ll fumble with keybindings for a week—but the productivity gains are permanent. Start with basic sessions and splits, add features as you need them.