Skip to main content
tmux

Copy Mode

Step 6 of 8

Copy Mode

Copy mode lets you scroll through terminal output, search for text, and copy to a clipboard — all without a mouse.

This is essential when:

  • You need to scroll back through long output
  • You want to copy error messages or commands
  • You're working on a remote server without mouse support
NOTE:

Copy mode is like less or vim for your terminal output.

Entering copy mode

Enter copy mode:

$

You can now scroll up from your current position.

NOTE:

Copy mode shows output that has scrolled off screen. You can't copy what's currently visible — for that, just select text in your terminal emulator.

Scrolling

Line by line:

$
$

Page by page:

$
# page up
$
# page down

$
$

Jump to top/bottom:

$
# go to top
$
# go to bottom

Searching

Search forward:

$

Type your search term, press Enter. Press n for next match, N for previous.

Search backward:

$

Same behavior, but searches upward.

NOTE:

Search supports regex. Use \bword\b for whole-word matches.

Copying text

  1. Enter copy mode: Ctrl-b [
  2. Navigate to start position with arrow keys or search
  3. Start selection: Space
  4. Move to end position (text is highlighted)
  5. Copy selection: Enter

The text is now in tmux's paste buffer.

Pasting

Paste the last copied text:

$

This works in any pane or window — paste is session-wide.

Vi mode vs Emacs mode

Copy mode uses vi keys by default. If you prefer emacs:

From command line:

$
NOTE:

Vi mode is more powerful but requires learning vi. Emacs mode uses familiar arrow keys.

Copy mode commands (vi mode)

KeyAction
h j k lLeft, down, up, right
w bForward/backward by word
0 $Start/end of line
g GStart/end of buffer
/ ?Search forward/backward
n NNext/previous search result
SpaceStart selection
EnterCopy selection and exit
q EscExit without copying

Copy mode commands (emacs mode)

KeyAction
Arrow keys
Ctrl-b Ctrl-fPage up/down
Ctrl-a Ctrl-eStart/end of line
Alt-< Alt->Start/end of buffer
Ctrl-s Ctrl-rSearch forward/backward
Ctrl-SpaceStart selection
Ctrl-wCopy selection
EnterCopy selection
EscExit

Paste buffers

tmux keeps multiple paste buffers. List them:

$

Use arrow keys to select, Enter to paste.

Copying between sessions

By default, paste buffers are per-session. To share across sessions:

$

Type: set-buffer -b shared "text"

Then in another session:

$

Type: paste-buffer -b shared

Configuring scrollback

Increase scrollback history:

$

Type: set-option -g history-limit 10000

NOTE:

Set this permanently in .tmux.conf: set -g history-limit 10000

Clearing history

Clear scrollback history:

$

Type: clear-history

Capturing pane

Save entire pane contents to file:

$
  • -S -: Start from beginning
  • -E -: End at end
  • > output.txt: Redirect to file

Scrolling with mouse

tmux supports mouse scrolling (requires configuration):

$

Type: set-option -g mouse on

Now you can:

  • Scroll with mouse wheel
  • Click to position cursor
  • Select and copy with mouse
NOTE:

Mouse mode is convenient but slow. Keyboard-only is faster once learned.

Practical examples

Copy error message:

# Run failing command
npm test

# Enter copy mode
Ctrl-b [

# Search for "Error"
/
Error

# Copy the error
Space (select)
Enter (copy)

# Paste elsewhere
Ctrl-b ]

Copy command from earlier:

# Scroll back
Ctrl-b [
k (up)

# Select command line
Space
0 (start of line)
$ (end of line)
Enter (copy)

# Paste to execute
Ctrl-b ]

Copy mode workflows

Reviewing build output:

  1. Build runs, scrolls off screen
  2. Enter copy mode: Ctrl-b [
  3. Search for "error" or "warning": /error
  4. Review each match with n
  5. Copy specific error to report

Extracting data:

  1. Run command with table output
  2. Enter copy mode, navigate to table
  3. Copy rows with Space ... Enter
  4. Paste into file or spreadsheet

Documenting commands:

  1. Run successful command sequence
  2. Enter copy mode
  3. Copy each command with 0 $ Enter
  4. Paste into documentation

Key bindings summary

KeyAction
Ctrl-b [Enter copy mode
Ctrl-b ]Paste buffer
Ctrl-b =Choose buffer
SpaceStart selection
EnterCopy selection
qExit copy mode
/Search forward
?Search backward
n NNext/previous match

Next: Step 7 → Configuration — Customize tmux with .tmux.conf