Prefix and basic concepts

The essentials for getting started
P
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
  • tmux Start new session.
  • tmux ls List all sessions.
  • tmux new -s nombre New session with name.
  • tmux attach -t nombre Join session.
  • tmux detach Desacoplar (desde dentro de tmux).
  • tmux rename-session -t nombre1 nombre2 Rename session.
  • tmux switch -t nombre Switch to session.
  • tmux kill-session -t nombre Delete session by name.
  • tmux kill-server Delete 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.0 Join pane 2.1 to 1.0.
  • break-pane Convert pane to window.
  • swap-pane -[UDLR] Exchange pane address.
  • select-pane -t :.+ Select next pane.
  • set-window-option synchronize-panes on Synchronize 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 2 Swap with window 2.
  • move-window -t 3 Move to window 3.
  • link-window -s src -t dst Link window between sessions.
  • unlink-window Unlink window.
  • kill-window Close 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-buffer Mostrar buffer principal.
  • :list-buffers List all buffers.
  • :save-buffer file Save buffer to file.
  • :delete-buffer -b N Delete buffer N.
  • set -g mode-keys vi Use Vim keys in copy mode.
Copy-mode shortcuts
  • Prefix[ Enter copy mode.
  • q Exit copy mode.
  • Space Start selection.
  • Enter Copy selection.
  • Page Up / Page Down Scroll up/down.
  • / Search ahead.
  • ? Search back.
  • n / N Next/previous search result.

Resize and layout

Predefined layouts and quick settings
Layouts
  • select-layout even-horizontal Horizontally distributed panes.
  • select-layout even-vertical Vertically distributed panes.
  • select-layout main-horizontal Main pane above, others below.
  • select-layout main-vertical Main pane on the left.
  • select-layout tiled All 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 on Enable mouse to resize, select, etc.
  • set -g mouse off Disable mouse support.
  • setw -g mode-mouse on Enable 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 MiSesion Decoupled session.
  • tmux send-keys -t MiSesion 'top' Enter Send command to pane.
  • tmux new-window -t MiSesion:1 -n 'htop' Create window called htop.
  • tmux split-window -h -t MiSesion:1 Split window horizontally.
  • tmux select-pane -t MiSesion:1.0 Select 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+b try Ctrl+b twice.
  • Copy/paste not working?Use set -g mouse on and try Shift + Mouse or enable clipboard with plugin tmux-yank.
  • Wrong terminal colors?Check set -g default-terminal "screen-256color" in ~/.tmux.conf and in your terminal emulator.
  • Share tmux?Run tmux attach -t session from multiple terminals (same user).

Plugins and more resources

Extend tmux and keep learning