tmux Tutorial: Master Terminal Multiplexing

3 min read
#tmux#terminal#productivity#dev-tools

Introduction to tmux

tmux is a terminal multiplexer that lets you:

  • Create multiple terminal sessions in one window
  • Split windows into panes
  • Detach and reattach sessions (keep processes running)

Key Concepts

  • Session: A collection of windows under one tmux instance
  • Window: A tab-like container within a session
  • Pane: A split section within a window

Basic Usage

Starting tmux

tmux                        # Start new session with default name
tmux new -s mysession       # Start named session
tmux attach -t mysession    # Attach to existing session
tmux ls                     # List all sessions

Prefix Key

All tmux shortcuts use a prefix key. Default is Ctrl+b (press and release, then press the command key).

Essential Commands

Session Management

ShortcutAction
Ctrl+b dDetach from session
Ctrl+b $Rename session
Ctrl+b sList sessions
Ctrl+b (Previous session
Ctrl+b )Next session

Window Management

ShortcutAction
Ctrl+b cCreate new window
Ctrl+b ,Rename window
Ctrl+b nNext window
Ctrl+b pPrevious window
Ctrl+b 0-9Go to window number
Ctrl+b wList windows
Ctrl+b &Close window

Pane Management

ShortcutAction
Ctrl+b %Split vertically
Ctrl+b "Split horizontally
Ctrl+b ArrowMove between panes
Ctrl+b oCycle panes
Ctrl+b xClose pane
Ctrl+b SpaceToggle pane layouts
Ctrl+b {Move pane left
Ctrl+b }Move pane right
Ctrl+b zToggle zoom (expand/shrink pane)

Other Useful Commands

ShortcutAction
Ctrl+b ?Show all shortcuts
Ctrl+b :Enter command mode
Ctrl+b [Enter scroll/copy mode
Ctrl+b ]Paste from buffer
Ctrl+b tShow clock

Common Workflows

Split-screen development

tmux                     # Start tmux
Ctrl+b "                 # Split horizontally
# Run server in top pane
Ctrl+b Arrow             # Move to bottom pane
# Run client or tests below

Persistent session (keep processes running)

tmux new -s work         # Create session
# Run your long-running process
Ctrl+b d                 # Detach (process keeps running)
# ... do other work ...
tmux attach -t work      # Reattach later

Multiple project layouts

tmux new -s project1     # Session for project 1
# Set up windows/panes
Ctrl+b d                 # Detach
tmux new -s project2     # Session for project 2
# Switch between: tmux attach -t project1/project2

Configuration

Create ~/.tmux.conf for custom settings:

# Change prefix to Ctrl+a (easier for some)
set -g prefix C-a
unbind C-b

# Enable mouse mode
set -g mouse on

# Start window/pane numbering at 1
set -g base-index 1
setw -g pane-base-index 1

# Easier split shortcuts
bind v split-window -h -c "#{pane_current_path}"
bind h split-window -v -c "#{pane_current_path}"

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

# Improve colors
set -g default-terminal "screen-256color"

Quick Reference Commands

tmux kill-session -t name    # Kill a session
tmux kill-server             # Kill all sessions
tmux source-file ~/.tmux.conf # Reload config