Tmux Guide: Master Terminal Multiplexing for Productivity
Tmux is a powerful terminal multiplexer that allows you to create multiple sessions, windows, and panes within a single terminal window. It’s especially useful for remote servers, long-running processes, and organizing your development workflow.
Basic Installation and Configuration
Install Tmux on macOS:
brew install tmux
Install Tmux on Ubuntu/Debian:
sudo apt update && sudo apt install tmux
Enable Mouse Support (Highly Recommended):
echo "set -g mouse on" >> ~/.tmux.conf
This allows you to click between panes, resize them, and scroll with your mouse/trackpad.
After making changes to ~/.tmux.conf, reload the configuration with:
tmux source-file ~/.tmux.conf
Session Management
- Create a new session:
tmux new -s session_name
- List active sessions:
tmux ls
- Attach to an existing session:
tmux attach -t session_name
- Detach from current session (session continues running in background):
Ctrl + BthenD - Kill a specific session:
tmux kill-session -t session_name
- Kill all sessions (use with caution):
tmux kill-server
Keyboard Shortcuts (Prefix: Ctrl + B)
All tmux commands start with the prefix key combination: Ctrl + B. Press and release it before pressing the command key.
Window Management
- Create new window:
Ctrl + BthenC - Switch to next window:
Ctrl + BthenN - Switch to previous window:
Ctrl + BthenP - List all windows:
Ctrl + BthenW - Close current window:
Ctrl + Bthen&
Pane Management
- Split pane vertically:
Ctrl + Bthen% - Split pane horizontally:
Ctrl + Bthen" - Switch between panes:
Ctrl + Bthen arrow keys (↑ ↓ ← →) - Resize current pane:
Ctrl + BthenCtrl + ↑(resize up)Ctrl + BthenCtrl + ↓(resize down)Ctrl + BthenCtrl + ←(resize left)Ctrl + BthenCtrl + →(resize right)- Zoom in/out current pane:
Ctrl + BthenZ - Close current pane:
Ctrl + BthenX
Other Useful Shortcuts
- Show key bindings help:
Ctrl + Bthen? - Rename current window:
Ctrl + Bthen, - Rename current session:
Ctrl + Bthen$ - Scroll mode (for viewing history):
Ctrl + Bthen[ - Use arrow keys or mouse wheel to scroll
- Press
Qto exit scroll mode
Additional Useful Commands
Create a session with a specific name and run a command:
tmux new -s dev -d "npm run dev"
Attach to the last session:
tmux attach
Switch between sessions quickly:
Ctrl + BthenS(shows session list)
Send command to all panes in a window:
tmux setw synchronize-panes on
(Run your command, then turn off with off)
Custom .tmux.conf recommendations (add these for better experience):
# Improve colors
set -g default-terminal "screen-256color"
# Faster key repetition
set -s escape-time 0
# Start windows and panes at 1, not 0
set -g base-index 1
setw -g pane-base-index 1
# Vim-style pane navigation
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
Pro Tips
- Running servers: Use tmux when running
npm run dev,python manage.py runserver, or any long-running process so you can safely disconnect from SSH. - Named sessions: Use descriptive names like
api,frontend,database,logs. - Plugin Manager (advanced): Consider TPM for installing community plugins.