Traversing scrollback and copy mode: vi-style navigation, forward and backward search, selection, yank, and paste, clipboard integration via OSC 52 and tmux-yank, up to buffer management with list-buffers and capture-pane.

In episode 4 we dissected the prefix key and built a must-know keybinding map — including prefix + , which we haven't used yet. This episode lifts one of the abilities that makes tmux feel like a text editor on top of a terminal: copy mode, the ability to browse the entire scrollback, search, select, copy, and paste text without touching the mouse. In episode 4 we only touched prefix + ?, which uses copy mode to display the keybinding list; here we'll tear it apart completely.
Why is this ability so important in the real world? Because an engineer's life is full of output that doesn't fit on screen: long tracebacks from failed processes, hundreds of lines of production application logs, terraform plan results exceeding one terminal page. In a plain terminal, old output is lost forever once scrolled past; in tmux, everything is stored in the scrollback buffer and can be hunted down at any time. Add proper clipboard integration, and your workflow changes drastically: from "manually retyping from the screen" to "search, yank, paste" in seconds — even when working on a remote server over SSH, where the local clipboard is normally unreachable.
The behavior we'll learn is consistent in tmux 3.7b (the latest stable release at the time of writing) — copy mode is an old feature that stays relevant because the core problem never changes: people need to take text off the terminal screen. Let's start by understanding where that text is stored.
Tmux doesn't throw away output that has scrolled past the screen. Each pane stores its output in a scrollback buffer — a ring buffer that keeps the last lines ever shown in that pane. When the buffer fills up, the oldest lines are overwritten by new ones. Imagine a looping tape recorder: what you hear at the end is the newest, but you can rewind as far as the tape's capacity allows.
That tape capacity is controlled by the history-limit option, defaulting to 2,000 lines per pane. Two thousand lines sounds like a lot, but a single docker logs or one long stack trace can eat a third of it in a flash. That's why practitioners raise it — we'll set it permanently in episode 6 — but for now the important thing is to understand its nature: scrollback is per pane, separate from the shell's history, and only stores lines that were actually displayed. You can't scroll back to before the pane was created.
The simplest way to browse scrollback is to scroll with the mouse wheel if mouse on is enabled. But mouse scrolling only displays — to search, select with precision, and copy, you must enter copy mode, which has its own, far more powerful controls than a mouse wheel.
Copy mode is a mode inside tmux that turns the active pane from a "passive screen" into a "navigable document". Enter with prefix + [; exit with q or Enter. A shortcut used even more often: prefix + PgUp enters copy mode directly and scrolls one page — this combination is the first reflex you should train when output flies past the screen.
Inside copy mode, tmux hands you full keyboard control. There are two navigation styles: emacs (tmux's built-in default) and vi. Both keep the same keys with the same logic — the difference is key placement and w/b — and the choice between them is a matter of habit. For the majority of engineers already familiar with vim, switching to vi style makes everything feel like home.
set -g mode-keys vi
set -g set-clipboard on
set -g history-limit 10000The three lines above are the foundation of productive copy mode: mode-keys vi enables vim-style navigation, set-clipboard on connects yank results to the system clipboard (we'll dissect this in the clipboard integration section), and history-limit 10000 expands the scrollback so large output isn't lost.
Inside copy mode, movement follows vim logic: j/k move down/up a line, h/l shift left/right, w/b jump a word, g/G go to the start/end of the scrollback. For fast movement, Ctrl+u/Ctrl+d scroll half a page and Ctrl+f/Ctrl+b a full page. All of this works without your hands leaving the home row — that's why, once used to it, you won't go back to mouse scrolling.
Searching in copy mode is like in vim: press / then type the pattern and Enter to search forward, or ? to search backward. n and N jump to the next/previous result. The real power emerges when the pattern is a regex — for example, finding all lines with level ERROR in a long log: /ERROR\.*\|WARN. This is an instant grep replacement for output still warm on the screen.
Selecting in vi mode: press Space to start a selection at the cursor position, move the cursor to expand, y to yank (copy into the tmux buffer), and Enter to yank and exit copy mode at once. Selection variants: v character selection, V whole-line selection, b rectangular block selection — blocks are very useful for columns of numbers or tables. After yanking, the text is stored in the tmux buffer; paste with prefix + ]. You can also select with the mouse if set -g mouse on is enabled — the selection is copied automatically when you release the mouse button.
| Key (vi) | Action |
|---|---|
j / k | Down / up one line |
h / l | Shift left / right one column |
w / b | Jump one word forward / backward |
Ctrl+u / Ctrl+d | Scroll half a page |
Ctrl+f / Ctrl+b | Scroll a full page |
g / G | Jump to start / end of scrollback |
/ / ? | Search forward / backward |
n / N | Next / previous search result |
Space | Start selection |
v / V / b | Character / line / block selection |
y | Yank (copy to buffer) |
Enter | Yank and exit copy mode |
q | Exit without copying |
The question that immediately arises: after y, where does the text go? tmux's built-in answer is the internal buffer — available for prefix + ] in the same session, but not automatically into the OS clipboard. To get it out to the OS clipboard, there are three approaches with different levels of convenience.
OSC 52 is a standard terminal escape sequence that lets applications inside the terminal — including tmux — write to the system clipboard over the terminal protocol. The amazing part: because the protocol flows through the terminal, it works across SSH. You can copy text from a production server on the other side of the world and have it land directly in your laptop's clipboard. The option set -g set-clipboard on makes yank results be sent as OSC 52 to the terminal emulator. The requirement is that your terminal emulator supports it — iTerm2, WezTerm, Kitty, Konsole, and modern Windows Terminal already do; most other Linux terminals are catching up.
For full control, you can install the tmux-yank plugin (in episode 16 we'll manage plugins via TPM). This plugin adds prefix + y to copy directly to the system clipboard, prefix + Y to copy the current command line, and y inside copy mode to yank to the system clipboard and exit at once. It works with xclip/xsel (X11), wl-copy (Wayland), or pbcopy (macOS), and automatically uses OSC 52 as a fallback when no local utility is found — an ideal combination for those mixing local and remote work.
| Approach | How It Works | Requirement | When It Fits |
|---|---|---|---|
| tmux internal buffer | Yank stored in the tmux buffer | None | Paste with prefix + ] in the same session |
set-clipboard on | tmux sends OSC 52 to the terminal | Terminal supports OSC 52 | Remote work via SSH |
| tmux-yank | Writes to OS clipboard via xclip/pbcopy | TPM + clipboard utility | Local Linux/macOS workflows |
Tip
To test your terminal's OSC 52 support, run this command from a plain shell (outside tmux): printf '\e]52;c;%s\a' "$(printf 'halo dari OSC 52' | base64)". If the text appears in your clipboard after running it, your terminal is ready to use set-clipboard on to its full potential.
Tmux stores every yank result in a buffer stack — think of it like a vim register or the OS copy stack, where the newest buffer sits on top. Understanding how to manage this stack turns copy mode from "single copy-paste" into a small automation tool.
tmux list-buffers shows the contents of all buffers, newest first, in the format buffer1: 42 bytes: "...". When there are many buffers and you want to choose visually, tmux choose-buffer opens an interactive mode: scroll, select, Enter to paste it. This is the fastest way out of the "which one did I just yank?" confusion.
Buffers aren't just for reading: tmux save-buffer -b buffer1 /tmp/yanked.txt saves a buffer's contents to a file — a practical way to get text from the screen to disk without manual pasting. Conversely, tmux set-buffer "teks" writes text from outside into a buffer, so it can be pasted with prefix + ]. For quick inspection, tmux show-buffer -b buffer1 prints the buffer contents to the screen.
The most useful command for debugging: tmux capture-pane -p -S - captures the entire scrollback of the active pane and prints it to stdout. Without -S -, it only captures the visible screen; with -S -, the whole buffer is captured too. Redirect it to a file, pipe it to grep or rg, or paste it into an issue tracker — output that once just flashed across the screen now becomes a processable artifact.
tmux list-buffers
tmux choose-buffer
tmux show-buffer -b buffer1The last line in the third block shows the real power: the -t 0:1.2 flag targets a specific pane — window 1, pane 2, in session 0. That means you can capture output from a pane that isn't even active, from a script or from the command prompt. For DevOps engineers, this is the standard way to pull logs from a running session for analysis without disturbing it.
Yank then expect Ctrl+v to paste directly. Yank results go into the tmux buffer by default, not the OS clipboard. Paste with prefix + ], or enable set-clipboard on and the tmux-yank plugin so the system clipboard gets filled too.
Assuming the scrollback is unlimited. history-limit defaults to only 2,000 lines. Output that passes beyond the buffer's capacity is gone forever — increase the limit in your config, especially for panes running log-heavy applications.
Not understanding emacs vs vi mode-keys. Navigation keys differ between the two styles, so "why won't j work?" is usually because you're still in emacs mode. Set set -g mode-keys vi once and remove the ambiguity forever.
Thinking a remote clipboard is impossible. With OSC 52 (set-clipboard on), copying from an SSH server to the local clipboard works as long as your terminal supports it. Don't give up on the "manual mouse copy" workflow before testing this.
Assuming capture-pane captures the entire history. Without the -S - flag, the command only captures the visible screen. Always include -S - for the whole scrollback, or you'll lose the part you actually wanted to capture.
Using prefix + ] for the wrong buffer. prefix + ] pastes the newest buffer; if the stack is full, make sure the correct buffer is selected via choose-buffer or list-buffers.
This episode turned tmux from a "screen splitter" into a "terminal with memory". You understand the scrollback buffer as a per-pane ring buffer expandable with history-limit, mastered copy mode with vi-style navigation — j/k, w/b, g/G, / and ? search, Space/v/V/b selection, up to yank and paste with prefix + ]. You also know how to get yank results out to the system clipboard: set-clipboard on for cross-SSH OSC 52, or the tmux-yank plugin for full control with xclip/pbcopy. Finally, you have buffer management weapons: list-buffers, choose-buffer, save-buffer, set-buffer, and capture-pane -S - to capture any pane's output.
Key points to take away:
prefix + [ or prefix + PgUp.set -g mode-keys vi) unifies navigation with your vim habits.set-clipboard on enables OSC 52 — cross-SSH copying without extra tools.list-buffers, choose-buffer, and save-buffer keep it under control.capture-pane -p -S - captures the whole scrollback to grep, save, or report.Now you can take anything off the screen — including from sessions you're not even looking at. In episode 6 we put all the habits you've gathered into one permanent place: the basic ~/.tmux.conf configuration — from the file location and the bind-key/set-option grammar to a reload workflow without restarting. See you in episode 6!