tmux Copy Mode: Copy, Paste & Clipboard Guide
Master tmux copy mode for copying text, searching through terminal output, and integrating with your system clipboard. Covers vi and emacs key bindings, selection modes, and buffer management.
Dai Aoki
CEO at init, Inc. / CTO at US & JP startups / Creator of WebTerm
What is Copy Mode?
tmux copy mode allows you to scroll through terminal output, search for text, and copy content to a buffer or your system clipboard. It is essential when you need to copy output from the terminal without reaching for the mouse.
By default, tmux does not let you scroll back through the output of a pane. Copy mode solves this by turning the current pane into a scrollable buffer where you can navigate, select, and copy text using keyboard shortcuts.
| Action | Key Binding |
|---|---|
| Enter copy mode | prefix + [ |
| Exit copy mode (vi mode) | q |
| Exit copy mode (emacs mode) | Escape |
Once inside copy mode, you can freely move around the buffer, search for text, select regions, and copy them. The copied text is stored in a tmux paste buffer and can also be sent to your system clipboard with the right configuration.
Vi vs Emacs Mode
tmux supports two key binding styles for copy mode: vi and emacs. The default is emacs mode. If you are a vim user, switching to vi mode is highly recommended as the key bindings will feel natural and consistent with your editor workflow.
# Set vi mode for copy mode key bindings (recommended for vim users)
setw -g mode-keys vi
# Set emacs mode (this is the default)
setw -g mode-keys emacs
# Check current mode
tmux show-option -gw mode-keysAdd the setw -g mode-keys vi line to your ~/.tmux.conf to make it persistent. This guide primarily covers vi mode key bindings, with emacs equivalents noted where appropriate.
Navigation in Copy Mode
Once you enter copy mode with prefix + [, you can navigate through the buffer using the following keys depending on your mode setting.
Vi Mode Navigation
| Key | Action |
|---|---|
| h / j / k / l | Move left / down / up / right |
| w / b | Move forward / backward by word |
| 0 / $ | Move to beginning / end of line |
| g / G | Move to top / bottom of buffer |
| Ctrl+u / Ctrl+d | Scroll half-page up / down |
| Ctrl+b / Ctrl+f | Scroll full page up / down |
Emacs Mode Navigation
| Key | Action |
|---|---|
| Arrow keys | Move in any direction |
| Ctrl+a / Ctrl+e | Move to beginning / end of line |
| Alt+< / Alt+> | Move to top / bottom of buffer |
| Ctrl+v / Alt+v | Scroll page down / up |
Selecting and Copying Text
In vi mode, selecting and copying text follows a flow similar to vim's visual mode. You navigate to the start of the text you want, begin a selection, move to the end, and then yank (copy) it.
| Key (vi mode) | Action |
|---|---|
| Space | Start selection |
| Enter | Copy selection and exit copy mode |
| v | Begin character selection (with config below) |
| V | Begin line selection |
| Ctrl+v | Toggle rectangle (block) selection (with config below) |
The default key bindings for selection in vi mode can be improved by adding vim-like bindings. Here is the recommended configuration to add to your ~/.tmux.conf:
# Enable vi mode
setw -g mode-keys vi
# vim-like selection key bindings
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-toggleWith this configuration, the copy workflow becomes:
- Press
prefix + [to enter copy mode - Navigate to the start of the text you want to copy
- Press
vto begin selection (orVfor line selection) - Move to the end of the text to extend the selection
- Press
yto yank (copy) the selection - Press
prefix + ]to paste
System Clipboard Integration
By default, tmux copies text to its own internal paste buffer, not to your system clipboard. To integrate with the system clipboard, you need to pipe the copied text to a clipboard command specific to your operating system.
macOS (pbcopy)
On macOS, use pbcopy to send copied text to the system clipboard:
# macOS: copy to system clipboard
bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "pbcopy"
# Also copy on mouse drag end (if mouse mode is enabled)
bind -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "pbcopy"Linux X11 (xclip / xsel)
On Linux with X11, use xclip or xsel to access the system clipboard:
# Linux X11 with xclip
bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "xclip -selection clipboard"
# Linux X11 with xsel (alternative)
bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "xsel --clipboard --input"
# Install xclip or xsel if not present
# Debian/Ubuntu: sudo apt install xclip
# Fedora: sudo dnf install xclip
# Arch: sudo pacman -S xclipLinux Wayland (wl-copy)
On Linux with Wayland, use wl-copy from the wl-clipboard package:
# Linux Wayland
bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "wl-copy"
# Install wl-clipboard if not present
# Debian/Ubuntu: sudo apt install wl-clipboard
# Fedora: sudo dnf install wl-clipboard
# Arch: sudo pacman -S wl-clipboardCross-Platform Configuration
If you use the same ~/.tmux.conf across macOS and Linux machines, you can use if-shell to automatically detect the platform and choose the correct clipboard command:
# Cross-platform clipboard integration
if-shell "uname | grep -q Darwin" \
'bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "pbcopy"' \
'bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "xclip -selection clipboard"'As an easier alternative, the tmux-yank plugin automatically detects your platform and configures clipboard integration for you. If you use TPM (Tmux Plugin Manager), simply add it to your plugin list:
# Add to ~/.tmux.conf
set -g @plugin 'tmux-plugins/tmux-yank'
# Then install with: prefix + ISearching in Copy Mode
Copy mode includes a search feature that works similarly to vim search. This is useful for finding specific text in your scrollback buffer, such as error messages or log entries.
| Key (vi mode) | Action |
|---|---|
| / | Search forward |
| ? | Search backward |
| n | Jump to next match |
| N | Jump to previous match |
# Example search workflow:
# 1. Enter copy mode: prefix + [
# 2. Press / to start forward search
# 3. Type your search term and press Enter
# 4. Press n to jump to the next match
# 5. Press N to jump to the previous match
# 6. Press q to exit copy modeIn emacs mode, use Ctrl+s for forward search and Ctrl+r for reverse search. The n and N keys work the same way to cycle through matches.
Buffer Management
tmux maintains a stack of paste buffers. Every time you copy text in copy mode, it is pushed onto this buffer stack. You can list, view, save, and paste from these buffers using tmux commands.
| Command / Key | Action |
|---|---|
| tmux list-buffers | Show all paste buffers |
| tmux show-buffer | Display contents of the latest buffer |
| tmux save-buffer file.txt | Save the latest buffer to a file |
| prefix + ] | Paste the latest buffer |
| prefix + = | Choose a buffer to paste from a list |
| tmux delete-buffer | Delete the latest buffer |
# List all paste buffers with their contents
tmux list-buffers
# Show the content of the most recent buffer
tmux show-buffer
# Save the most recent buffer to a file
tmux save-buffer ~/copied-output.txt
# Save a specific buffer (by index) to a file
tmux save-buffer -b 0 ~/buffer0.txt
# Load a file into the paste buffer
tmux load-buffer ~/some-text.txt
# Delete all buffers
tmux delete-buffer -aThe buffer chooser (prefix + =) opens an interactive list where you can preview each buffer and select one to paste. This is especially useful when you have copied multiple pieces of text and need to paste an earlier selection.
Practical Examples
Here are common real-world scenarios where copy mode is indispensable.
Copying a Command Output
When you run a command and need to copy part of its output (for example, a file path or a hash), copy mode lets you do it entirely from the keyboard:
# 1. Run your command
git log --oneline -5
# 2. Enter copy mode: prefix + [
# 3. Navigate to the commit hash you want (use k to go up, w to move by word)
# 4. Press v to start selection
# 5. Move to select the hash (e.g., press e to go to end of word)
# 6. Press y to copy
# 7. Paste with: prefix + ]Copying an Error Message
Error messages often span multiple lines. Use line selection to grab the whole block:
# 1. Enter copy mode: prefix + [
# 2. Navigate to the first line of the error
# 3. Press V to start line selection
# 4. Press j to extend the selection down across all error lines
# 5. Press y to copy all selected lines
# 6. Paste into a bug report or chat with: prefix + ]Searching for a Specific Log Entry
When debugging, you often need to find a specific log entry in a long output stream:
# 1. Enter copy mode: prefix + [
# 2. Press ? to search backward (since errors are usually recent)
# 3. Type "ERROR" and press Enter
# 4. Press n/N to cycle through matches until you find the right one
# 5. Press v to start selection, then navigate to select the relevant text
# 6. Press y to copyCopying Multi-Line Content
Rectangle (block) selection is useful when you need to copy a column of data from formatted output:
# 1. Enter copy mode: prefix + [
# 2. Navigate to the top-left corner of the block you want
# 3. Press Ctrl+v to toggle rectangle selection mode
# 4. Press v to start selection
# 5. Navigate to the bottom-right corner of the block
# 6. Press y to copy the rectangular selectionComplete Recommended Configuration
Here is a complete copy mode configuration that you can add to your ~/.tmux.conf:
# Vi mode for copy mode
setw -g mode-keys vi
# vim-like key bindings for selection
bind -T copy-mode-vi v send-keys -X begin-selection
bind -T copy-mode-vi C-v send-keys -X rectangle-toggle
bind -T copy-mode-vi V send-keys -X select-line
# System clipboard integration (choose your platform)
# macOS
if-shell "uname | grep -q Darwin" \
'bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "pbcopy"'
# Linux (X11)
if-shell "[ -n \"\$DISPLAY\" ]" \
'bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "xclip -selection clipboard"'
# Increase scrollback buffer size (default is 2000)
set -g history-limit 50000Official Documentation
For authoritative information, refer to the official documentation:
Related Articles
tmux - Terminal Multiplexer
Terminal multiplexer for session management and window splitting
tmux Cheat Sheet: All Key Bindings & Commands
Complete tmux cheat sheet with all keyboard shortcuts, commands, and quick reference tables for sessions, windows, panes, and copy mode.
tmux.conf Configuration Guide: Customize Your tmux
Complete tmux.conf configuration guide. Learn prefix key customization, key bindings, status bar styling, mouse settings, true color, performance tuning, and workflow-specific configs.
tmux Plugins Guide: TPM, Resurrect, Continuum & More
Complete guide to tmux plugins. Learn TPM (Tmux Plugin Manager) setup, essential plugins like resurrect, continuum, sensible, yank, and vim-navigator with best practices.