Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save cumulus13/5ccafdd626b030d08902c9c23cb3b0e0 to your computer and use it in GitHub Desktop.

Select an option

Save cumulus13/5ccafdd626b030d08902c9c23cb3b0e0 to your computer and use it in GitHub Desktop.
Complete tmux Shortcuts & Cheatsheet

Complete tmux Shortcuts & Cheatsheet

Table of Contents

Basic Concepts

Default Prefix Key: Ctrl+b (can be changed to Ctrl+a in config)

Command Format: <prefix> + key means press Ctrl+b, release, then press the key

tmux Hierarchy:

Server → Sessions → Windows → Panes

CLI Arguments & Commands

Basic tmux Command Structure

tmux [options] [command [flags]]

Global Options

Option Description
-2 Force tmux to assume 256-color terminal
-8 Force tmux to assume 88-color terminal
-c shell-command Execute shell-command using default shell
-f file Specify alternative configuration file
-l Behave as a login shell
-L socket-name Store socket in different location
-S socket-path Specify full socket path
-u Write UTF-8 output to terminal
-v Request verbose logging
-V Print version and exit

Session Commands

Command Options Description
new-session -A, -d, -D, -P, -s name, -t target, -x width, -y height Create new session
attach-session -d, -r, -t target Attach to session
detach-client -a, -P, -s target, -t target Detach client
has-session -t target Check if session exists
kill-session -a, -t target Kill session
list-sessions -f filter, -F format List sessions
lock-session -t target Lock session
rename-session -t target newname Rename session
switch-client -c target, -l, -n, -p, -r, -t target Switch client to session

Session Command Examples

# Create new session
tmux new-session -s mysession
tmux new -s mysession -d                    # detached
tmux new -s mysession -c /path/to/dir       # with working directory
tmux new -s mysession -x 120 -y 40          # with specific dimensions

# Attach to session
tmux attach-session -t mysession
tmux attach -t mysession -d                 # detach other clients first
tmux attach -t mysession -r                 # read-only mode

# List sessions
tmux list-sessions
tmux ls -F "#{session_name}: #{session_windows} windows"

# Kill sessions
tmux kill-session -t mysession
tmux kill-session -a                        # kill all except current
tmux kill-session -a -t mysession           # kill all except specified

Window Commands

Command Options Description
new-window -a, -c start-directory, -d, -n window-name, -t target Create new window
kill-window -a, -t target Kill window
list-windows -a, -f filter, -F format, -t target List windows
move-window -a, -d, -r, -s src, -t dst Move window
rename-window -t target newname Rename window
respawn-window -c start-directory, -k, -t target Restart window
rotate-window -D, -t target Rotate window panes
select-window -l, -n, -p, -t target Select window
split-window -b, -c start-directory, -d, -f, -h, -v, -p percentage, -t target Split window
swap-window -d, -s src, -t dst Swap windows
unlink-window -k, -t target Unlink window

Window Command Examples

# Create windows
tmux new-window -n editor vim
tmux new-window -c /var/log -n logs         # with working directory
tmux new-window -a                          # after current window
tmux new-window -t mysession:3              # at specific index

# Split windows
tmux split-window -h                        # horizontal split
tmux split-window -v                        # vertical split  
tmux split-window -h -p 30                  # 30% width
tmux split-window -v -c /tmp                # with working directory
tmux split-window -h -d                     # don't switch to new pane

# Move/swap windows
tmux move-window -t 5                       # move to index 5
tmux swap-window -s 1 -t 3                  # swap window 1 and 3

Pane Commands

Command Options Description
break-pane -d, -n window-name, -s src-pane, -t dst-window Break pane into window
capture-pane -a, -e, -p, -P, -S start, -E end, -t target Capture pane content
display-panes -d duration, -t target Display pane numbers
find-window -C, -N, -T, -t target pattern Find window containing text
join-pane -b, -d, -h, -v, -p percentage, -s src, -t dst Join pane to window
kill-pane -a, -t target Kill pane
list-panes -a, -f filter, -F format, -s, -t target List panes
move-pane -b, -d, -h, -v, -p percentage, -s src, -t dst Move pane
pipe-pane -o, -t target [command] Pipe pane output to command
resize-pane -D, -L, -R, -U, -t target, -x width, -y height Resize pane
respawn-pane -c start-directory, -k, -t target Restart pane
select-pane -D, -L, -R, -U, -l, -t target Select pane
swap-pane -d, -D, -U, -s src, -t dst Swap panes

Pane Command Examples

# Break/join panes
tmux break-pane -s mysession:1.2            # break pane 2 from window 1
tmux join-pane -s mysession:2 -t 1          # join window 2 as pane to window 1
tmux join-pane -h -p 25 -s 2.1 -t 1.1       # horizontal join, 25% width

# Resize panes
tmux resize-pane -D 5                       # expand down 5 lines
tmux resize-pane -L 10 -t 1                 # shrink left 10 columns, pane 1
tmux resize-pane -x 80 -y 24                # absolute size

# Capture pane content
tmux capture-pane -p                        # print to stdout
tmux capture-pane -t mysession:1.2 -S -1000 # last 1000 lines

Client Commands

Command Options Description
detach-client -a, -P, -s session, -t client Detach client
list-clients -f filter, -F format, -t session List clients
lock-client -t client Lock client
refresh-client -C width,height, -S, -t client Refresh client
suspend-client -t client Suspend client
switch-client -c target-client, -l, -n, -p, -r, -t target Switch client

Buffer Commands

Command Options Description
choose-buffer -f filter, -F format, -t target Choose buffer interactively
clear-history -t target Clear pane history
copy-mode -M, -u, -t target Enter copy mode
delete-buffer -b buffer-name Delete buffer
list-buffers -f filter, -F format List paste buffers
load-buffer -b buffer-name file Load buffer from file
paste-buffer -b buffer-name, -d, -p, -r, -s separator, -t target Paste buffer
save-buffer -a, -b buffer-name file Save buffer to file
set-buffer -a, -b buffer-name, -n new-buffer-name Set buffer content
show-buffer -b buffer-name Display buffer content

Server Commands

Command Options Description
info Display server information
kill-server Kill tmux server
list-commands -f filter, -F format List tmux commands
lock-server Lock server
refresh Refresh all clients
source-file -q file Execute commands from file
start-server Start tmux server

Key Binding Commands

Command Options Description
bind-key -c, -n, -r, -T table, -x Bind key to command
list-keys -T table List key bindings
send-keys -l, -M, -R, -t target Send keys to pane
send-prefix -2, -t target Send prefix key
unbind-key -a, -n, -T table Unbind key

Key Binding Examples

# Bind keys
tmux bind-key h select-pane -L              # bind h to select left pane
tmux bind-key -r j resize-pane -D           # bind j to resize down (repeatable)
tmux bind-key -n C-h select-pane -L         # bind without prefix

# Send keys
tmux send-keys -t mysession:1 'ls -la' Enter
tmux send-keys -t 1.2 C-c                   # send Ctrl+C to pane 2

Option Commands

Command Options Description
set-option -a, -g, -o, -q, -s, -u, -w Set session/window option
set-window-option -a, -g, -o, -q, -u Set window option
show-options -A, -g, -H, -q, -s, -v, -w Show options
show-window-options -g, -v Show window options

Option Examples

# Set options
tmux set-option -g prefix C-a               # global prefix key
tmux set-option -g mouse on                 # enable mouse globally
tmux set-window-option -g mode-keys vi      # vi keys in copy mode

# Show options
tmux show-options -g                        # show global options
tmux show-options -g prefix                 # show specific option

Environment Commands

Command Options Description
set-environment -g, -r, -u Set environment variable
show-environment -g, -s, -t target Show environment

Advanced CLI Usage

# Multiple commands in one line
tmux new-session -d -s dev \; split-window -h \; select-pane -t 0

# Conditional execution
tmux has-session -t mysession 2>/dev/null && tmux attach -t mysession || tmux new -s mysession

# Format strings for output
tmux list-sessions -F "Session: #{session_name} (#{session_windows} windows)"
tmux list-panes -F "#{pane_id}: #{pane_current_command} in #{pane_current_path}"

# Using tmux in scripts
#!/bin/bash
if ! tmux has-session -t work 2>/dev/null; then
    tmux new-session -d -s work -c ~/projects
    tmux split-window -h -c ~/projects
    tmux new-window -c ~/logs -n logs
fi
tmux attach-session -t work

Common Format Variables

Variable Description
#{session_name} Session name
#{session_windows} Number of windows in session
#{window_name} Window name
#{window_index} Window index
#{pane_id} Pane identifier
#{pane_current_command} Current command in pane
#{pane_current_path} Current path in pane
#{client_width} Client width
#{client_height} Client height

Session Management

Creating & Attaching Sessions

Command Description
tmux Start new session
tmux new -s <name> Start new session with name
tmux new -s <name> -d Start new detached session
tmux ls List all sessions
tmux list-sessions List all sessions (verbose)
tmux attach Attach to last session
tmux attach -t <name> Attach to named session
tmux a -t <name> Attach to named session (short)

Inside tmux Session

Shortcut Description
<prefix> + d Detach from session
<prefix> + D Choose session to detach
<prefix> + s List and switch sessions
<prefix> + $ Rename current session
<prefix> + ( Switch to previous session
<prefix> + ) Switch to next session
<prefix> + L Switch to last used session

Killing Sessions

Command Description
tmux kill-session -t <name> Kill named session
tmux kill-session -a Kill all sessions except current
tmux kill-server Kill tmux server and all sessions
<prefix> + x Kill current pane/window

Window Management

Creating & Navigation

Shortcut Description
<prefix> + c Create new window
<prefix> + , Rename current window
<prefix> + n Next window
<prefix> + p Previous window
<prefix> + l Switch to last used window
<prefix> + w List windows (interactive)
<prefix> + f Find window by name
<prefix> + 0-9 Switch to window by number
<prefix> + ' Switch to window by number (prompt)

Window Operations

Shortcut Description
<prefix> + & Kill current window
<prefix> + . Move current window (prompt for number)
<prefix> + < Move window left
<prefix> + > Move window right

Window Monitoring

Shortcut Description
<prefix> + M Monitor window for activity
<prefix> + m Monitor window for silence

Pane Management

Creating & Splitting

Shortcut Description
<prefix> + % Split pane horizontally (left/right)
<prefix> + " Split pane vertically (top/bottom)
<prefix> + c Create new window (single pane)

Navigation

Shortcut Description
<prefix> + ←↑↓→ Navigate between panes
<prefix> + h/j/k/l Navigate panes (vim-style, if configured)
<prefix> + o Switch to next pane
<prefix> + ; Switch to last used pane
<prefix> + q Show pane numbers
<prefix> + q + 0-9 Switch to pane by number

Resizing Panes

Shortcut Description
<prefix> + Ctrl+←↑↓→ Resize pane in direction
<prefix> + Alt+←↑↓→ Resize pane in direction (5 cells)
<prefix> + z Toggle pane zoom (full screen)

Pane Operations

Shortcut Description
<prefix> + x Kill current pane
<prefix> + ! Break pane into new window
<prefix> + { Move current pane left
<prefix> + } Move current pane right
<prefix> + Ctrl+o Rotate panes clockwise
<prefix> + Alt+o Rotate panes counter-clockwise

Pane Layouts

Shortcut Description
<prefix> + Space Cycle through predefined layouts
<prefix> + Alt+1 Even horizontal layout
<prefix> + Alt+2 Even vertical layout
<prefix> + Alt+3 Main horizontal layout
<prefix> + Alt+4 Main vertical layout
<prefix> + Alt+5 Tiled layout

Pane Synchronization

Shortcut Description
:setw synchronize-panes on Synchronize input to all panes
:setw synchronize-panes off Turn off synchronization
<prefix> + : Enter command mode

Copy Mode & Scrolling

Entering Copy Mode

Shortcut Description
<prefix> + [ Enter copy mode
<prefix> + PgUp Enter copy mode and scroll up

Navigation in Copy Mode (vi-mode)

Shortcut Description
h/j/k/l Move cursor left/down/up/right
w/b Move word forward/backward
0/$ Move to start/end of line
g/G Move to start/end of buffer
Ctrl+b/Ctrl+f Page up/down
/ Search forward
? Search backward
n/N Next/previous search result

Selection & Copying (vi-mode)

Shortcut Description
Space Start selection
Enter Copy selection and exit copy mode
v Start visual selection
V Start line-wise selection
y Copy selection
Escape Clear selection
q Exit copy mode

Emacs-mode Copy Commands

Shortcut Description
Ctrl+Space Start selection
Ctrl+w Copy selection
Alt+w Copy selection (alternative)

Pasting

Shortcut Description
<prefix> + ] Paste last copied text
<prefix> + = Choose buffer to paste from
<prefix> + # List paste buffers

Status Bar & Monitoring

Status Bar Controls

Shortcut Description
<prefix> + t Show time
<prefix> + i Display window information

Command Mode

Shortcut Description
<prefix> + : Enter command mode
:source-file ~/.tmux.conf Reload configuration
:list-keys List all key bindings
:list-commands List all commands
:show-options -g Show global options
:show-options -w Show window options

Configuration

Basic .tmux.conf Settings

# Change prefix key to Ctrl+a
set -g prefix C-a
unbind C-b
bind C-a send-prefix

# Enable mouse support
set -g mouse on

# Vi mode for copy mode
setw -g mode-keys vi

# Start windows and panes at 1, not 0
set -g base-index 1
setw -g pane-base-index 1

# Renumber windows when one is closed
set -g renumber-windows on

# Increase scrollback buffer
set -g history-limit 10000

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

# Status bar customization
set -g status-bg black
set -g status-fg white
set -g status-left '[#S] '
set -g status-right '%Y-%m-%d %H:%M'

# Pane border colors
set -g pane-border-style fg=black
set -g pane-active-border-style fg=red

# Window activity monitoring
setw -g monitor-activity on
set -g visual-activity on

Custom Key Bindings

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

# Vim-style 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

# Split panes more intuitively
bind | split-window -h
bind - split-window -v

# Quick pane synchronization toggle
bind S setw synchronize-panes

# Easy config reload
bind r source-file ~/.tmux.conf \; display-message "Config reloaded!"

Advanced Features

Session Management Scripts

# Create development session
tmux new-session -d -s dev
tmux split-window -h
tmux split-window -v
tmux select-pane -t 0
tmux send-keys 'vim' C-m
tmux select-pane -t 1
tmux send-keys 'npm start' C-m
tmux select-pane -t 2

Tmux Plugin Manager (TPM)

# Add to ~/.tmux.conf
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-resurrect'

# Initialize TPM (keep at bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'

Useful Environment Variables

Variable Description
$TMUX Set when inside tmux session
$TMUX_PANE Current pane identifier
$TMUX_SESSION Current session name

Integration with System Clipboard

# macOS
bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel 'pbcopy'
bind -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel 'pbcopy'

# Linux (xclip)
bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel 'xclip -in -selection clipboard'
bind -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel 'xclip -in -selection clipboard'

Troubleshooting

Common Issues

Problem Solution
Colors not working Set TERM=screen-256color or xterm-256color
Mouse scroll not working Add set -g mouse on to config
Prefix key not working Check if another program is using Ctrl+b
Session not found Use tmux ls to list available sessions
Config not loading Use tmux source-file ~/.tmux.conf

Debug Commands

Command Description
tmux info Show tmux server information
tmux list-keys List all key bindings
tmux show-options -g Show global options
tmux display-message -p '#S' Display current session name

Performance Tips

  • Limit history buffer size: set -g history-limit 5000
  • Disable activity monitoring for better performance
  • Use tmux kill-server to restart if sluggish
  • Avoid too many panes in a single window

Quick Reference Card

Essential Commands

Sessions:  tmux new -s name | tmux attach -t name | tmux ls
Windows:   <prefix> + c (new) | <prefix> + n/p (navigate) | <prefix> + , (rename)
Panes:     <prefix> + % (h-split) | <prefix> + " (v-split) | <prefix> + o (navigate)
Copy:      <prefix> + [ (enter) | Space (select) | Enter (copy) | <prefix> + ] (paste)
Other:     <prefix> + d (detach) | <prefix> + z (zoom) | <prefix> + ? (help)

Most Used Shortcuts

  1. <prefix> + c - New window
  2. <prefix> + d - Detach session
  3. <prefix> + % - Split horizontally
  4. <prefix> + " - Split vertically
  5. <prefix> + o - Switch pane
  6. <prefix> + n/p - Switch window
  7. <prefix> + z - Toggle zoom
  8. <prefix> + [ - Copy mode
  9. <prefix> + ] - Paste
  10. <prefix> + ? - Help

This cheatsheet covers tmux 3.x. Some features may vary in older versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment