π₯οΈ tmux Cheat Sheet #
π What is tmux? #
tmux (Terminal Multiplexer) is a powerful command-line tool that allows you to:
- Create multiple terminal sessions within a single window
- Detach and reattach to sessions (survive SSH disconnections)
- Split windows into panes for multitasking
- Share sessions between multiple users
- Keep processes running in the background
π Installation #
Ubuntu/Debian #
sudo apt update
sudo apt install tmux
CentOS/RHEL/Fedora #
# CentOS/RHEL 7
sudo yum install tmux
# CentOS/RHEL 8+ / Fedora
sudo dnf install tmux
macOS #
brew install tmux
Verify Installation #
tmux -V
ποΈ Core Concepts #
Hierarchy #
- Session: Collection of windows (like a workspace)
- Window: Collection of panes (like browser tabs)
- Pane: Individual terminal instance (split screen)
Prefix Key #
Default prefix: Ctrl-b (press before any tmux command)
All shortcuts below assume you press Ctrl-b first
π― Essential Commands #
Session Management #
# Start new session
tmux
tmux new
tmux new-session
# Start named session
tmux new-session -s mysession
# List sessions
tmux list-sessions
tmux ls
# Attach to session
tmux attach-session -t mysession
tmux a -t mysession
# Attach to last session
tmux attach
# Switch between sessions
tmux switch -t mysession
# Kill session
tmux kill-session -t mysession
# Kill all sessions
tmux kill-server
Key Bindings (Prefix + Key) #
Session Control #
d- Detach from sessions- List and switch sessions$- Rename current session(- Switch to previous session)- Switch to next session
Window Management #
c- Create new windown- Next windowp- Previous window0-9- Switch to window by numberw- List windows,- Rename current window&- Kill current windowf- Find window by name
Pane Management #
%- Split horizontally (left/right)"- Split vertically (top/bottom)arrow keys- Navigate between paneso- Cycle through panesq- Show pane numbersx- Kill current panez- Toggle pane zoom (fullscreen)!- Break pane into new window{- Move pane left}- Move pane rightCtrl+arrow- Resize pane
Copy Mode & Scrollback #
[- Enter copy mode (scroll/search)]- Paste from tmux bufferqorEsc- Exit copy mode
Copy Mode Navigation (vi-style) #
k/β- Up one linej/β- Down one lineh/β- Left one characterl/β- Right one characterCtrl-u- Half page upCtrl-d- Half page downCtrl-b- Full page upCtrl-f- Full page downg- Go to topG- Go to bottom/- Search forward?- Search backwardSpace- Start selectionEnter- Copy selection
System #
?- List all key bindings:- Command promptr- Reload config filet- Show clock
βοΈ Configuration (.tmux.conf) #
Create ~/.tmux.conf for persistent settings:
# Basic Settings
set -g default-terminal "screen-256color"
set -g history-limit 10000
set -g base-index 1
set -g pane-base-index 1
# Enable mouse support
set -g mouse on
# Faster command sequences
set -s escape-time 0
# Reload config file
bind r source-file ~/.tmux.conf \; display-message "Config reloaded!"
# Better prefix key (optional)
unbind C-b
set -g prefix C-a
bind C-a send-prefix
# Vi-style copy mode
setw -g mode-keys vi
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi y send-keys -X copy-selection-and-cancel
# Pane navigation like vim
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
# Pane resizing
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
# Better splitting
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
# Status bar customization
set -g status-bg black
set -g status-fg white
set -g status-left-length 20
set -g status-left '#[fg=green]#S #[fg=yellow]#I #[fg=cyan]#P'
set -g status-right '#[fg=yellow]%Y-%m-%d %H:%M'
# Window status
setw -g window-status-current-style 'fg=black bg=white bold'
setw -g window-status-style 'fg=white bg=black'
# Pane borders
set -g pane-border-style 'fg=colour238'
set -g pane-active-border-style 'fg=colour51'
π Plugin Manager (TPM) #
Installation #
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
Add to .tmux.conf #
# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'
# Initialize TMUX plugin manager (keep at bottom)
run '~/.tmux/plugins/tpm/tpm'
Plugin Management #
Prefix + I- Install pluginsPrefix + U- Update pluginsPrefix + Alt + u- Uninstall plugins
Popular Plugins #
- tmux-sensible: Sensible defaults
- tmux-resurrect: Save/restore sessions
- tmux-continuum: Automatic session saving
- tmux-yank: Copy to system clipboard
- tmux-pain-control: Better pane management
π¨ Advanced Features #
Session Scripting #
#!/bin/bash
# Create development session
tmux new-session -d -s dev
tmux split-window -h
tmux select-pane -t 0
tmux send-keys 'vim' C-m
tmux select-pane -t 1
tmux send-keys 'npm run dev' C-m
tmux attach-session -t dev
Custom Key Bindings #
# Quick session switching
bind-key -r f run-shell "tmux neww ~/.local/bin/tmux-sessionizer"
# Send commands to all panes
bind-key a set-window-option synchronize-panes
# Quick layouts
bind-key M-1 select-layout even-horizontal
bind-key M-2 select-layout even-vertical
bind-key M-3 select-layout main-horizontal
bind-key M-4 select-layout main-vertical
bind-key M-5 select-layout tiled
Copy to System Clipboard #
# macOS
bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel 'pbcopy'
# Linux
bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel 'xclip -in -selection clipboard'
π οΈ Troubleshooting #
Common Issues #
- Colors not working: Add
alias tmux='tmux -2'to shell config - Mouse not working: Ensure
set -g mouse onin config - Config not loading: Check file location and syntax
- Prefix not working: Verify no conflicts with shell shortcuts
Debugging #
# Check current settings
tmux show-options -g
tmux show-window-options -g
# List key bindings
tmux list-keys
# Check tmux info
tmux info
π‘ Pro Tips #
Workflow Optimization #
- Use named sessions for different projects
- Set up project templates with predefined layouts
- Use mouse mode for quick pane switching
- Customize status bar with useful information
- Learn copy mode for efficient text selection
Performance #
- Increase history limit for long-running processes
- Use
set -s escape-time 0for faster key response - Disable unused features to reduce memory usage
Integration #
- SSH: Sessions survive connection drops
- Git: Show branch in status bar
- Docker: Run containers in separate panes
- Monitoring: Use panes for logs, metrics, etc.
π Useful Commands #
Information #
tmux info # System information
tmux list-commands # All available commands
tmux show-messages # Recent messages
tmux display-message '#S' # Show session name
Advanced Session Management #
# Create session with specific directory
tmux new-session -s project -c ~/projects/myapp
# Create detached session
tmux new-session -d -s background
# Send commands to session
tmux send-keys -t mysession 'ls -la' C-m
# Capture pane content
tmux capture-pane -t mysession -p > output.txt
Layouts #
# Predefined layouts
tmux select-layout even-horizontal
tmux select-layout even-vertical
tmux select-layout main-horizontal
tmux select-layout main-vertical
tmux select-layout tiled
# Custom layout
tmux select-layout "main-horizontal,162x48,0,0{81x48,0,0,0,80x48,82,0,1}"
π Resources #
Master tmux and transform your terminal workflow! π