Skip to content

SOP-005: Copy Mode

Fresh
FieldValue
Document IDSOP-005
Version1.1
StatusActive
tmux Version3.6b
Last Updated2026-05-26

Purpose

Navigate scrollback history, search text, and copy/paste content within tmux.

Prerequisites

  • tmux installed (SOP-001)
  • Active tmux session

Copy Mode Overview

Procedure

Entering Copy Mode

MethodAction
Ctrl+b [Enter copy mode
Ctrl+b PgUpEnter copy mode and scroll up

Add to ~/.tmux.conf:

bash
setw -g mode-keys vi

This enables vi-style navigation in copy mode.

KeyAction
h j k lMove cursor left/down/up/right
wForward one word
bBack one word
0Start of line
$End of line
gGo to top
GGo to bottom
Ctrl+uPage up
Ctrl+dPage down

Searching

KeyAction
/Search forward
?Search backward
nNext match
NPrevious match

Selecting Text

KeyAction
SpaceStart selection
vStart selection (vi mode)
VSelect line (vi mode)
Ctrl+vRectangle selection
EscClear selection
EnterCopy selection

Copy Workflow

  1. Enter copy mode: Ctrl+b [
  2. Navigate to where you want to start copying
  3. Start selection: Space (or v in vi mode)
  4. Navigate to end of selection
  5. Copy: Enter
  6. Paste: Ctrl+b ]

Pasting

MethodAction
Ctrl+b ]Paste most recent buffer
:paste-bufferPaste buffer
:choose-bufferChoose buffer to paste

Buffer Management

bash
# Show buffer contents
:show-buffer

# List all buffers
:list-buffers

# Save buffer to file
:save-buffer filename.txt

# Load file to buffer
:load-buffer filename.txt

# Delete specific buffer
:delete-buffer -b 1

# Choose buffer interactively
:choose-buffer

Capturing Pane Content

bash
# Capture visible pane content
:capture-pane

# Capture with history
:capture-pane -S -1000    # Last 1000 lines

# Capture and save to file
:capture-pane -S - -E - -p > output.txt

Copy Mode Quick Reference

Emacs Keys (Default)

KeyAction
Ctrl+SpaceStart selection
Ctrl+wCopy selection
Alt+wCopy selection
Ctrl+gClear selection
Ctrl+sSearch forward
Ctrl+rSearch backward

Vi Keys (After setw -g mode-keys vi)

KeyAction
vStart selection
yCopy selection (yank)
EnterCopy selection
EscClear selection
/Search forward
?Search backward

Enhanced Vi Copy Mode

Add to ~/.tmux.conf for better vi-style copying:

bash
# Vi mode
setw -g mode-keys vi

# 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 r send-keys -X rectangle-toggle

# Copy to system clipboard (macOS)
bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "pbcopy"

# Copy to system clipboard (Linux with xclip)
# bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "xclip -selection clipboard"

Copy Mode Enhancements New in 3.6

tmux 3.6 added several copy mode improvements:

Search in modes now matches the copy mode convention: an all lowercase search term searches case insensitively (emacs style). Type any uppercase letter to make the search case sensitive. No configuration needed.

Selection Mode Command

The selection-mode command sets the selection mode explicitly while in copy mode, instead of toggling through rectangle/line/character. Bind it in copy-mode-vi if you want a dedicated key:

bash
# Example: jump straight to block (rectangle) selection
bind-key -T copy-mode-vi C-v send-keys -X selection-mode block

Centre the Cursor

New commands recenter the viewport on the cursor in copy mode, like zz in vim. Bind a key to the centre command for quick reorientation in long scrollback.

Copy Without Clipboard or Buffer

Copy commands accept two new flags:

FlagEffect
-CDo not send the copied text to the clipboard
-PDo not add the copied text as a paste buffer
bash
# Copy to a pipe only, skip clipboard and paste buffer
bind-key -T copy-mode-vi Y send-keys -X -C -P copy-pipe "wc -l"

Quieter Confirmations

The -y flag disables confirmation prompts in modes, useful for scripted or fast workflows.

Position and Selection Styling

Three new options control the look of copy mode:

bash
set -g copy-mode-position-style 'fg=#000000,bg=#89b4fa'
set -g copy-mode-selection-style 'fg=#000000,bg=#a6e3a1'
set -g copy-mode-position-format '#{scroll_position}/#{history_size}'

Mouse wheel

In tmux 3.6 the mouse wheel no longer enters copy mode while an application is using the alternate screen (for example less or vim), so scrolling passes through to the application as expected.

Verification

Test copy/paste workflow:

bash
# 1. Enter copy mode
Ctrl+b [

# 2. You should see [0/0] in the top-right

# 3. Navigate with arrows or vi keys

# 4. Press q to exit

# 5. Check buffers
:list-buffers

Troubleshooting

Can't scroll in copy mode

Solution

Make sure you're in copy mode (Ctrl+b [). The indicator [0/0] should appear in the corner.

Vi keys not working

Solution

Enable vi mode in your config:

bash
# Add to ~/.tmux.conf
setw -g mode-keys vi

# Reload config
tmux source-file ~/.tmux.conf

Paste not working

Solution

Make sure you copied something first. Check buffers:

bash
:list-buffers

If empty, nothing was copied.

Need to copy to system clipboard

Solution

Use clipboard integration:

macOS:

bash
# In ~/.tmux.conf
bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "pbcopy"

Linux (with xclip):

bash
bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "xclip -sel clip"

See Also

Generated with AI-powered SOP Generator