Skip to main content

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)

Set vi mode in your config:

~/.tmux.conf
setw -g mode-keys vi
KeyAction
h j k lMove cursor left/down/up/right
Ctrl+fScroll down one page
Ctrl+bScroll up one page
Ctrl+dScroll down half page
Ctrl+uScroll up half page
gGo to top of scrollback
GGo to bottom (latest output)
0Go to start of line
$Go to end of line
wJump forward by word
bJump 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.

What's Next