M
MeshWorld.
Cheatsheet tmux Terminal Linux Bash Developer Tools Productivity 9 min read

tmux Cheat Sheet: Sessions, Panes, Windows & Config

Jena
By Jena
| Updated: Mar 28, 2026

The one thing to understand first

Every tmux command starts with the prefix keyCtrl+b by default. You press the prefix, release it, then press the command key. It’s a two-step chord, not a simultaneous press.

Most people remap the prefix to Ctrl+a (easier to reach). The .tmux.conf section below shows how.


Quick reference tables

Sessions

CommandWhat it does
tmuxStart a new unnamed session
tmux new -s workStart a new session named work
tmux lsList all sessions
tmux attachAttach to the most recent session
tmux attach -t workAttach to session named work
tmux kill-session -t workKill session named work
tmux kill-serverKill all sessions and the tmux server
Prefix dDetach from current session (session keeps running)
Prefix $Rename current session
Prefix sInteractive session switcher
Prefix (Switch to previous session
Prefix )Switch to next session

Windows (tabs inside a session)

CommandWhat it does
Prefix cCreate a new window
Prefix ,Rename current window
Prefix &Close current window (with confirmation)
Prefix nNext window
Prefix pPrevious window
Prefix 0–9Switch to window by number
Prefix lSwitch to last (previously used) window
Prefix wInteractive window list
Prefix .Move window (prompts for index number)
Prefix fFind window by name

Panes (splits inside a window)

CommandWhat it does
Prefix %Split pane vertically (left/right)
Prefix "Split pane horizontally (top/bottom)
Prefix ←↑↓→Move to pane in that direction
Prefix oCycle through panes
Prefix qShow pane numbers (press number to jump)
Prefix xClose current pane (with confirmation)
Prefix zToggle pane zoom (fullscreen)
Prefix !Break pane out into its own window
Prefix {Swap pane with the previous one
Prefix }Swap pane with the next one
Prefix Ctrl+←↑↓→Resize pane (hold Ctrl, tap arrow)
Prefix Alt+←↑↓→Resize pane in larger steps
Prefix SpaceCycle through built-in pane layouts

Copy mode

CommandWhat it does
Prefix [Enter copy mode
qExit copy mode
↑↓ or j kScroll (use vi keys after setting mode-keys vi)
Ctrl+b / Ctrl+fPage up / page down
g / GGo to top / bottom of buffer
/patternSearch forward
?patternSearch backward
n / NNext / previous search match
SpaceStart selection (vi mode)
EnterCopy selection and exit copy mode
Prefix ]Paste copied text

Miscellaneous

CommandWhat it does
Prefix :Open tmux command prompt
Prefix ?Show all key bindings
Prefix tShow clock in current pane
Prefix ~Show tmux messages
Prefix iShow current window info
tmux source ~/.tmux.confReload config without restarting
Prefix rReload config (if bound in .tmux.conf)

Detailed sections

How tmux works — the mental model

tmux has three levels of hierarchy:

Server
└── Session (named, persists after detach)
    └── Window (like browser tabs)
        └── Pane (splits within a window)

You can have multiple sessions, each with multiple windows, each with multiple panes. When you detach (Prefix d), the session keeps running on the server — your SSH connection can drop and everything inside tmux survives.

The Scenario: You’re SSH’d into a remote server running a long build. Your internet cuts out. Without tmux, the build dies. With tmux, you re-attach when you’re back and the build is still running. This alone is worth learning tmux.

Practical workflow — named sessions

Start your day by creating named sessions for each context:

# Create sessions for each project/context
tmux new -s infra
tmux new -s dev
tmux new -s logs

# Later, list them
tmux ls
# infra: 1 windows (created Fri Mar 28 09:00:01 2026)
# dev: 3 windows (created Fri Mar 28 09:01:44 2026)
# logs: 1 windows (created Fri Mar 28 09:02:10 2026)

# Jump to a specific session
tmux attach -t dev

Inside a session, organize windows by task. Prefix c for a new window, Prefix , to rename it.

# Inside tmux — rename the current window to "api"
Prefix ,
# type "api", press Enter

The Scenario: You’re juggling three things: an API server, a database shell, and a log tail. One tmux session, three windows named api, db, logs. Switch between them with Prefix 1, Prefix 2, Prefix 3. No more terminal window hunting.

Copy mode and the clipboard

Copy mode uses vi or emacs keys depending on your config. Vi keys are more useful for developers already in the Vim world.

First, set vi keys in .tmux.conf:

setw -g mode-keys vi

Then the copy flow in vi mode:

Prefix [          → enter copy mode
/search-term      → search for text
Space             → start selection
Move cursor       → extend selection
Enter             → copy and exit
Prefix ]          → paste

To integrate with the system clipboard on Linux (requires xclip):

# In .tmux.conf
bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "xclip -in -selection clipboard"

On macOS (uses pbcopy):

# In .tmux.conf
bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "pbcopy"

Now pressing y in copy mode copies to the system clipboard instead of just the tmux buffer.

A production-ready .tmux.conf

This config remaps the prefix, enables mouse support, sets vi keys, improves the status bar, and adds useful shortcuts. Save it to ~/.tmux.conf.

# ── Prefix ──────────────────────────────────────────────────
# Remap prefix from Ctrl+b to Ctrl+a (easier to reach)
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix

# ── General ─────────────────────────────────────────────────
set -g default-terminal "screen-256color"  # 256-color support
set -g history-limit 50000                 # scroll back 50k lines
set -g display-time 4000                   # message display duration (ms)
set -g status-interval 5                   # refresh status bar every 5s
set -g focus-events on                     # pass focus events to apps

# Start windows and panes at index 1 (not 0 — easier to reach on keyboard)
set -g base-index 1
setw -g pane-base-index 1
set -g renumber-windows on                 # re-number windows when one closes

# ── Mouse ───────────────────────────────────────────────────
set -g mouse on                            # click to select panes, scroll, resize

# ── Vi keys in copy mode ────────────────────────────────────
setw -g mode-keys vi
bind -T copy-mode-vi v send-keys -X begin-selection
bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "xclip -in -selection clipboard"

# ── Splits ──────────────────────────────────────────────────
# More intuitive split keys: | for vertical, - for horizontal
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
unbind '"'
unbind %

# New windows and panes open in the current directory
bind c new-window -c "#{pane_current_path}"

# ── Pane navigation (vim-style) ─────────────────────────────
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

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

# ── Status bar ──────────────────────────────────────────────
set -g status-position bottom
set -g status-bg colour234
set -g status-fg colour137
set -g status-left '#[fg=colour233,bg=colour241,bold] #S '
set -g status-right '#[fg=colour233,bg=colour241] %H:%M #[fg=colour233,bg=colour245,bold] #h '
set -g status-right-length 50
set -g status-left-length 20
setw -g window-status-current-format '#[fg=colour81,bold] #I:#W '
setw -g window-status-format '#[fg=colour138] #I:#W '

After saving, reload with:

tmux source ~/.tmux.conf
# or inside tmux: Prefix r (once the reload bind is active)

tmux Plugin Manager (TPM)

TPM lets you install community plugins with a few lines of config. Install it first:

git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm

Add this to the bottom of .tmux.conf:

# ── Plugins (TPM) ───────────────────────────────────────────
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'    # sane defaults
set -g @plugin 'tmux-plugins/tmux-resurrect'   # save/restore sessions
set -g @plugin 'tmux-plugins/tmux-continuum'   # auto-save sessions every 15 min

# tmux-continuum: auto-restore on server start
set -g @continuum-restore 'on'

# Initialize TPM (keep this at the very bottom)
run '~/.tmux/plugins/tpm/tpm'

Reload the config, then press Prefix I (capital i) to install the plugins.

Key plugin shortcuts after install:

CommandWhat it does
Prefix Ctrl+sSave session (tmux-resurrect)
Prefix Ctrl+rRestore saved session (tmux-resurrect)
Prefix IInstall new plugins (TPM)
Prefix UUpdate plugins (TPM)
Prefix Alt+uRemove unlisted plugins (TPM)

The Scenario: Your laptop died mid-sprint. tmux-resurrect saved the session 15 minutes ago. You start fresh, press Prefix Ctrl+r, and your six panes with running processes come back exactly as they were. Not perfect, but close enough to matter.

tmux vs screen

Both are terminal multiplexers. Most developers should use tmux in 2026.

Featuretmuxscreen
Active developmentYesMinimal
Config file~/.tmux.conf~/.screenrc
Window splittingYes (horizontal + vertical)Vertical only (limited)
Mouse supportYesPartial
Scripting / automationStrongWeaker
Plugin ecosystemYes (TPM)No
Default on serversSometimesOften (older distros)

Use screen only if tmux isn’t available and you can’t install it. On any modern system you control, use tmux.

Related: Linux Bash Cheat Sheet | Vim Cheat Sheet | SSH & GPG Cheat Sheet