Tmux Command Cheatsheet
Tmux is a powerful terminal multiplexer that lets you create, access, and control multiple terminal sessions from a single window. This cheatsheet covers the most commonly used Tmux operations — session management, window navigation, pane layouts, configuration, and clipboard integration. Start with the prefix key (default Ctrl+b) and basic session operations, then gradually explore pane management and custom configuration.
Quick Reference
| Task | Key / Command |
| New session | tmux new -s name |
| Detach session | prefix + d |
| Reattach session | tmux attach -t name |
| New window | prefix + c |
| Switch window | prefix + number |
| Vertical split | prefix + % |
| Horizontal split | prefix + \" |
| Switch pane | prefix + arrow keys |
| Browse history | prefix + [ |
| List all keybindings | prefix + ? |
Session Management
``bash
# Create sessions
tmux new -s mysession # Create a new session named mysession
tmux new # Create an anonymous new session
tmux new-session -s web # Create a session named web
# Detach (leave running in background) prefix + d # Detach current session (programs keep running)
# Reattach tmux attach -t mysession # Reattach to mysession tmux a -t mysession # Short form tmux attach # Attach to the only session
# List sessions tmux ls # List all running sessions prefix + s # Interactive session selector inside Tmux
# Kill sessions tmux kill-session -t mysession # Kill a specific session tmux kill-server # Kill Tmux server (all sessions) prefix + & # Kill current window (with confirmation) prefix + x # Kill current pane (with confirmation)
# Rename tmux rename-session -t old new # Rename session from outside prefix + $ # Rename current session inside Tmux
# Switch sessions
prefix + ( # Switch to previous session
prefix + ) # Switch to next session
prefix + w # Menu-based session and window picker
`
Window Operations
`bash
# Create and close
prefix + c # Create a new window
prefix + & # Close current window (with confirmation)
tmux new-window -n web # Create a named window from command line
# Switch windows prefix + 0-9 # Switch to window by number prefix + p # Previous window prefix + n # Next window prefix + w # List-based window selector prefix + f # Find window by name
# Window management prefix + , # Rename current window prefix + . # Move window (enter new index) prefix + l # Switch to last active window :swap-window -t -1 # Swap with previous window :swap-window -t +1 # Swap with next window tmux move-window -s 1 -t 3 # Move window 1 to position 3
# Window indexing
tmux set -g base-index 1 # Start window index at 1 (default 0)
:move-window -r # Renumber windows sequentially
:display-message -p '#I' # Show current window index
`
Pane Operations
`bash
# Create panes
prefix + % # Vertical split (left/right panes)
prefix + " # Horizontal split (top/bottom panes)
:split-window -h # Command-based vertical split
:split-window -v # Command-based horizontal split
# Pane navigation prefix + ←↑→↓ # Navigate to adjacent pane prefix + o # Cycle to next pane prefix + ; # Go to last active pane prefix + q # Show pane numbers (press number to jump)
# Pane resizing prefix + Ctrl+arrow # Resize pane by 1 unit :resize-pane -D 10 # Resize down 10 lines :resize-pane -U 5 # Resize up 5 lines :resize-pane -L 20 # Resize left 20 columns :resize-pane -R 15 # Resize right 15 columns
# Pane control
prefix + ! # Break pane into a standalone window
prefix + x # Close current pane (with confirmation)
prefix + z # Toggle pane zoom (fullscreen/restore)
prefix + space # Cycle through pane layouts
prefix + { # Move pane left/up
prefix + } # Move pane right/down
prefix + q + number # Jump directly to pane by number
`
Layout Management
`bash
# Built-in layouts
prefix + space # Cycle through layouts
prefix + M-1 # even-horizontal layout
prefix + M-2 # even-vertical layout
prefix + M-3 # main-horizontal layout
prefix + M-4 # main-vertical layout
prefix + M-5 # tiled layout
:select-layout even-horizontal # Command-based layout selection :select-layout tiled # Tiled layout :select-layout -E # Previous layout
# Custom layout :setw -g window-layout tiled # Set default layout for new windows :setw -g force-width 80 # Force pane width :setw -g force-height 40 # Force pane height :join-pane -s web:2.1 # Move pane from session web window 2 pane 1 :join-pane -t .1 # Join current window pane 1 to new position :display-panes # Show all pane numbers
# Synchronized input :setw synchronize-panes on # Type simultaneously in all panes :setw synchronize-panes off # Disable synchronized input prefix + :setw synchronize-panes # Toggle via shortcut
# Save/restore layout
tmux list-windows -a # List all window layout info
:show-window-options -g # View global window options
:save-buffer ~/tmux-layout.txt # Save buffer to file
`
Configuration
`bash
# ~/.tmux.conf example
# Change prefix key
set -g prefix C-a # Change prefix to Ctrl+a
unbind C-b # Unbind default prefix
bind C-a send-prefix # Double-tap to send prefix
# Mouse support set -g mouse on # Enable mouse (click/drag/scroll)
# Appearance set -g default-terminal "screen-256color" # 256-color terminal support set -g status-bg colour235 # Status bar background set -g status-fg white # Status bar foreground set -g status-left-length 40 # Max left status length set -g status-right-length 80 # Max right status length set -g status-justify centre # Center-align status items set -g status-interval 5 # Status refresh interval (seconds)
# Status bar content set -g status-left "#[fg=green]Session: #S " set -g status-right "#[fg=yellow]%Y-%m-%d %H:%M " set -g window-status-current-format "#[fg=cyan,bold]#I:#W" set -g window-status-format "#[fg=white]#I:#W"
# Key binding optimizations bind r source-file ~/.tmux.conf \; display-message "Config reloaded" # Ctrl+b r reload bind | split-window -h # Use | for vertical split bind - split-window -v # Use - for horizontal split bind H resize-pane -L 5 # Quick resize left bind J resize-pane -D 5 # Quick resize down bind K resize-pane -U 5 # Quick resize up bind L resize-pane -R 5 # Quick resize right
# Display settings set -g display-time 3000 # Show messages for 3 seconds set -g message-style "bg=colour235,fg=white" set -g message-command-style "bg=colour235,fg=yellow"
# History buffer
set -g history-limit 50000 # Max history lines per pane
setw -g mode-keys vi # Use vi key bindings in copy mode
`
Clipboard & Copy Mode
`bash
# Enter copy mode
prefix + [ # Enter copy mode (scroll through history)
prefix + PageUp # Enter copy mode and scroll up
:capture-pane -S - # Capture full pane content to buffer
# Copy mode operations (vi mode) # Requires: setw -g mode-keys vi h / j / k / l # Move left / down / up / right Ctrl+b / Ctrl+f # Page up / page down gg / G # Go to top / bottom 0 / $ # Line start / end /pattern # Search forward ?pattern # Search backward n / N # Next / previous match
# Select and copy Space # Start text selection Enter # Copy selection to Tmux buffer prefix + ] # Paste from Tmux buffer
# Vi-style copy mode bindings (recommended) # bind -T copy-mode-vi v send-keys -X begin-selection # bind -T copy-mode-vi y send-keys -X copy-selection-and-cancel # bind -T copy-mode-vi C-v send-keys -X rectangle-toggle
# System clipboard integration # Linux (requires xclip) set -g set-clipboard on bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "xclip -selection clipboard" bind -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "xclip -selection clipboard"
# macOS (uses pbcopy) # 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"
# Buffer management :show-buffer # Show current buffer content :list-buffers # List all buffers :choose-buffer # Interactive buffer selector :save-buffer ~/output.txt # Save buffer to file :delete-buffer # Delete current buffer :clear-history # Clear current pane history ``
Session(7)
| Command | Level | ||
|---|---|---|---|
tmux new -s <name>Create a new named Tmux session | Basic | tmux new -s mysession | |
prefix + dDetach current session (programs keep running) | Basic | prefix + d | |
tmux attach -t <name>Reattach to a named session | Basic | tmux attach -t mysession | |
tmux lsList all running Tmux sessions | Basic | tmux ls | |
tmux kill-session -t <name>Kill a specific Tmux session | Basic | tmux kill-session -t mysession | |
tmux kill-serverKill the Tmux server and all sessions | Intermediate | tmux kill-server | |
prefix + $ / tmux rename-sessionRename the current session | Basic | prefix + $ |
Window(5)
| Command | Level | ||
|---|---|---|---|
prefix + cCreate a new window | Basic | prefix + c | |
prefix + 0-9Switch to window by index number | Basic | prefix + 1 | |
prefix + p / prefix + nSwitch to previous/next window | Basic | prefix + p | |
prefix + wBrowse and select windows from a list | Intermediate | prefix + w | |
prefix + , (comma)Rename the current window | Basic | prefix + , |
Pane(6)
| Command | Level | ||
|---|---|---|---|
prefix + "%"Split the current pane vertically (left/right) | Basic | prefix + "%" | |
prefix + '"'Split the current pane horizontally (top/bottom) | Basic | prefix + '"' | |
prefix + arrow keysNavigate to the adjacent pane by direction | Basic | prefix + ← | |
prefix + oCycle to the next pane | Basic | prefix + o | |
prefix + zToggle pane zoom (fullscreen/restore) | Basic | prefix + z | |
prefix + Ctrl+arrowResize pane by 1 unit in the given direction | Intermediate | prefix + Ctrl+↓ |
Layout(3)
| Command | Level | ||
|---|---|---|---|
prefix + spaceCycle through all pane layouts | Basic | prefix + space | |
prefix + M-1 / M-2 / M-3 / M-4 / M-5Select predefined layout (even-horizontal/even-vertical/main-horizontal/main-vertical/tiled) | Intermediate | prefix + M-5 | |
:setw synchronize-panes onSynchronize input across all panes | Expert | :setw synchronize-panes on |
Config(9)
| Command | Level | ||
|---|---|---|---|
set -g prefix C-aChange default prefix from Ctrl+b to Ctrl+a | Intermediate | set -g prefix C-a | |
set -g mouse onEnable mouse support (click/drag/scroll) | Basic | set -g mouse on | |
set -g default-terminal "screen-256color"Set terminal type for 256-color support | Intermediate | set -g default-terminal "screen-256color" | |
set -g status-interval 5Set status bar refresh interval in seconds | Intermediate | set -g status-interval 5 | |
set -g history-limit 50000Set maximum scrollback history lines per pane | Intermediate | set -g history-limit 50000 | |
setw -g mode-keys viUse vi-style key bindings in copy mode | Intermediate | setw -g mode-keys vi | |
bind r source-file ~/.tmux.confBind key to reload tmux configuration (prefix + r) | Intermediate | bind r source-file ~/.tmux.conf | |
set -g status-left "#[fg=green]Session: #S"Customize status bar left content (session name, etc.) | Expert | set -g status-left "#[fg=green]Session: #S " | |
set -g status-right "#[fg=yellow]%Y-%m-%d %H:%M"Customize status bar right content (date, time, etc.) | Expert | set -g status-right "#[fg=yellow]%Y-%m-%d %H:%M " |
Clipboard(10)
| Command | Level | ||
|---|---|---|---|
prefix + [Enter copy mode to scroll through history | Intermediate | prefix + [ | |
prefix + ]Paste content from Tmux buffer | Basic | prefix + ] | |
Space / EnterStart selection / copy selected text in copy mode | Intermediate | Space | |
bind -T copy-mode-vi y send-keys -X copy-selection-and-cancelBind vi-style y key to copy selection and exit copy mode | Expert | bind -T copy-mode-vi y send-keys -X copy-selection-and-cancel | |
bind -T copy-mode-vi v send-keys -X begin-selectionBind vi-style v key to begin text selection | Expert | bind -T copy-mode-vi v send-keys -X begin-selection | |
:capture-pane -S -Capture the entire pane content to buffer | Intermediate | :capture-pane -S - | |
:show-bufferDisplay current buffer contents | Intermediate | :show-buffer | |
:list-buffersList all Tmux buffers | Intermediate | :list-buffers | |
:save-buffer <file>Save buffer contents to a file | Intermediate | :save-buffer ~/output.txt | |
:clear-historyClear the current pane scrollback history | Intermediate | :clear-history |