The Ultimate tmux Guide and Cheat Sheet
Essential tmux commands organized by practical sections. Default prefix Ctrl + b.
Prefix and basic concepts
The essentials for getting started
Default prefix:
Ctrl + b (can be changed with set-option -g prefix C-a).
All the shortcuts that say Prefix assume Ctrl + b has been remapped.
Starting tmux and managing sessions
Create, list and manage sessions
Shell commands
tmuxStart new session.tmux lsList all sessions.tmux new -s nombreNew session with name.tmux attach -t nombreJoin session.tmux detachDesacoplar (desde dentro de tmux).tmux rename-session -t nombre1 nombre2Rename session.tmux switch -t nombreSwitch to session.tmux kill-session -t nombreDelete session by name.tmux kill-serverDelete all sessions (server).
Prefix shortcuts within tmux
Prefix: Open command prompt.Prefixd Undock from the session.Prefixs Session selector.Prefix$ Rename current session.Prefix? List key combinations.Prefix, Rename current window.Prefixw Windows selector.- To close the current session, use:
Prefix:kill-session
Panes
Split the terminal and move between panes
Pane management
Prefix% Split vertically.Prefix" Split horitzontally.Prefixo Go to the next pane.Prefix; Toggle between the last two panes.Prefix{ } Swap left/right pane.Prefixq Show pane numbers.Prefixz Zoom in pane.Prefixx Close current pane.Prefix! Promotes current pane to window.
Movement and advanced options
Prefix↑/↓/←/→ Move pane focus.PrefixAlt + ↑/↓/←/→ Resize pane.join-pane -s 2.1 -t 1.0Join pane 2.1 to 1.0.break-paneConvert pane to window.swap-pane -[UDLR]Exchange pane address.select-pane -t :.+Select next pane.set-window-option synchronize-panes onSynchronize panes.display-message '#P'Show pane index.
Windows and tabs
Organize work in multiple views
Window commands
rename-window new-nameRename current window.swap-window -t 2Swap with window 2.move-window -t 3Move to window 3.link-window -s src -t dstLink window between sessions.unlink-windowUnlink window.kill-windowClose window.display-message '#W'Show window name.
Window shortcuts using the prefix
Prefixc Create new window.Prefixp Previous window.Prefixn Next window.Prefix<0-9> Select window by number.Prefix& Delete current window.Prefix. Move window.Prefixf Search window by name.Prefixl Last window used.
Copy and scroll mode
History and text selection
Copy buffers and configuration
:show-bufferMostrar buffer principal.:list-buffersList all buffers.:save-buffer fileSave buffer to file.:delete-buffer -b NDelete buffer N.set -g mode-keys viUse Vim keys in copy mode.
Copy-mode shortcuts
Prefix[ Enter copy mode.qExit copy mode.SpaceStart selection.EnterCopy selection.Page Up/Page DownScroll up/down./Search ahead.?Search back.n/NNext/previous search result.
Resize and layout
Predefined layouts and quick settings
Layouts
select-layout even-horizontalHorizontally distributed panes.select-layout even-verticalVertically distributed panes.select-layout main-horizontalMain pane above, others below.select-layout main-verticalMain pane on the left.select-layout tiledAll mosaic panes.
Layout shortcuts
PrefixAlt + ↑/↓/←/→ Resize pane.Prefixspace Change pane layout.Prefixq Show pane numbers.Prefix{ } Swap left/right panes.Prefixz Active pane zoom/unzoom.
Mouse support
When you want to use the mouse
Configuration
set -g mouse onEnable mouse to resize, select, etc.set -g mouse offDisable mouse support.setw -g mode-mouse onEnable mouse in copy mode (tmux <2.1).
Practical use
- Drag the border to resize the pane.
- Click on the pane/window to focus.
- Scroll the mouse wheel to view the history.
Automation and scripting
Sessions prepared with a single command
Useful commands for scripts
tmux new-session -d -s MiSesionDecoupled session.tmux send-keys -t MiSesion 'top' EnterSend command to pane.tmux new-window -t MiSesion:1 -n 'htop'Create window called htop.tmux split-window -h -t MiSesion:1Split window horizontally.tmux select-pane -t MiSesion:1.0Select pane 0 in window 1.
Script example
# Script example
tmux new-session -d -s dev
tmux new-window -t dev:1 -n code
tmux send-keys -t dev:1 'vim .' C-m
tmux split-window -h -t dev:1
tmux send-keys -t dev:1.1 'npm start' C-m
tmux attach -t dev
Configuration file (~/.tmux.conf)
Shortcuts and recommended options
# Remapping prefix
set-option -g prefix C-a
unbind C-b
bind C-a send-prefix
# Mouse support
set -g mouse on
# Vim keys in copy mode
setw -g mode-keys vi
# 256-color support
set -g default-terminal "screen-256color"
# Useful titles
set -g set-titles on
set -g set-titles-string "#S:#I.#P #W"
# Shortcuts for splitting panes
bind | split-window -h
bind - split-window -v
# Reload configuration
bind r source-file ~/.tmux.conf \; display-message "Configuration reloaded!"
Tips and troubleshooting
Common troubleshooting issues- tmux not responding to keystrokes?It can be in a nested tmux session. The default prefix is
Ctrl+btryCtrl+btwice. - Copy/paste not working?Use
set -g mouse onand try Shift + Mouse or enable clipboard with plugintmux-yank. - Wrong terminal colors?Check
set -g default-terminal "screen-256color"in~/.tmux.confand in your terminal emulator. - Share tmux?Run
tmux attach -t sessionfrom multiple terminals (same user).
Plugins and more resources
Extend tmux and keep learning- TPM (tmux plugin manager) Easy plugin management.
- tmux-sensible Better default settings.
- tmux-resurrect Restore tmux sessions.
- tmux-continuum Continuous saving.
- tmux-yank Clipboard integration.
- Official tmux Wiki
- The Tao of tmux (free book)
- tmuxcheatsheet.com