Scrollback and Search
Copy mode is tmux's built-in pager for browsing terminal history. It lets you scroll back through output, search for strings, and select text to copy.
Core Idea
Tmux captures all pane output in a scrollback buffer. Copy mode lets you navigate this buffer using vi or emacs key bindings.
Entering Copy Mode
Ctrl+b [ → Enter copy mode
Ctrl+b PgUp → Enter copy mode and scroll up one page
The cursor becomes a text cursor. The pane enters a read-only scroll/navigation state.
Exiting Copy Mode
q → Exit copy mode (discard any selection)
Enter → Exit copy mode (finishes selection if active)
Navigation Keys (Vi Mode)
Set vi mode in your config:
~/.tmux.conf
setw -g mode-keys vi
| Key | Action |
|---|---|
h j k l | Move cursor left/down/up/right |
Ctrl+f | Scroll down one page |
Ctrl+b | Scroll up one page |
Ctrl+d | Scroll down half page |
Ctrl+u | Scroll up half page |
g | Go to top of scrollback |
G | Go to bottom (latest output) |
0 | Go to start of line |
$ | Go to end of line |
w | Jump forward by word |
b | Jump backward by word |
Searching in Copy Mode
/pattern → Search forward (press Enter to find, n to repeat)
?pattern → Search backward
n → Next match
N → Previous match
Example: searching for "error" in logs:
1. Enter copy mode: Ctrl+b [
2. Type: /error
3. Press: Enter
4. Jump to matches: n (next), N (previous)
5. Exit: q
Selecting and Copying Text (Vi Mode)
~/.tmux.conf
# Set up vi-style copy/paste
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi y send-keys -X copy-selection-and-cancel
bind-key -T copy-mode-vi V send-keys -X select-line
bind-key -T copy-mode-vi r send-keys -X rectangle-toggle
Workflow:
1. Enter copy mode: Ctrl+b [
2. Navigate to start
3. Press: v (begin selection)
4. Move: h/j/k/l to extend selection
5. Press: y (copy selection, exit mode)
6. Paste: Ctrl+b ]
Copying to System Clipboard
By default, tmux copies to its own internal buffer. To copy to the system clipboard:
~/.tmux.conf
# Linux (requires xclip or xsel)
bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "xclip -i -sel clipboard"
# macOS
bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "pbcopy"
Install clipboard utility:
sudo apt install -y xclip # Debian/Ubuntu
sudo dnf install -y xclip # RHEL/Fedora
note
On servers without a display, system clipboard integration is not useful. Use tmux's internal buffer and paste via Ctrl+b ].
Managing Tmux Paste Buffers
# List paste buffers
tmux list-buffers
# Paste specific buffer
Ctrl+b = # choose from list interactively
# Show last buffer content
tmux show-buffer
# Save buffer to file
tmux save-buffer ~/output.txt
Scrollback Buffer Size
~/.tmux.conf
# Set scrollback buffer (default is 2000 lines)
set -g history-limit 50000
For log-heavy work, 50000 or more is recommended.