Skip to main content

Copy-Paste Workflow

Tmux uses its own paste buffer system, separate from your terminal's clipboard. Understanding this workflow saves time and prevents frustration.

Learning Focus

Learn the three types of copy paths: tmux buffer, terminal native selection (Shift+drag), and system clipboard integration.

Three Ways to Copy in Tmux

MethodHowPaste with
Tmux buffer (copy mode)Ctrl+b [ → select → yCtrl+b ]
Terminal nativeHold Shift + click/dragMouse middle-click or terminal paste
System clipboardCopy mode → pipe to xclip/pbcopyOS paste (Ctrl+V or middle-click)

Method 1: Tmux Buffer (Standard)

1.  Ctrl+b [           → Enter copy mode
2. Navigate to text → use vim keys: h j k l / g G
3. v → start selection (vi mode)
4. Move to end → extend selection
5. y → copy to tmux buffer, exit mode
6. Ctrl+b ] → paste from buffer

Method 2: Terminal Native Selection

Hold Shift while using your mouse to select text. This bypasses tmux and uses your terminal emulator's native copy/paste:

  • Copy: Shift+click and drag, then Ctrl+Shift+C (or terminal-specific)
  • Paste: Ctrl+Shift+V or middle-click
note

This works even when tmux mouse mode is ON, because Shift bypasses tmux mouse capture.

Method 3: System Clipboard Integration

Add to ~/.tmux.conf:

~/.tmux.conf
# Linux with xclip
bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "xclip -i -sel clipboard"
bind-key -T copy-mode-vi MouseDragEnd1Pane 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"

Now y in copy mode sends to the system clipboard directly.

Multiple Buffers

Tmux keeps a history of copied buffers:

# List all buffers
tmux list-buffers

# Paste specific buffer (interactive list)
Ctrl+b =

# Paste buffer by index
tmux paste-buffer -b 0

# Show content of most recent buffer
tmux show-buffer

# Save buffer to a file
tmux save-buffer -b 0 ~/clipboard.txt

# Load file to buffer
tmux load-buffer ~/clipboard.txt

# Delete a buffer
tmux delete-buffer -b 0

Copying Multi-Line Content

Rectangle selection is useful for columns:

~/.tmux.conf
# Toggle rectangle selection with r
bind-key -T copy-mode-vi r send-keys -X rectangle-toggle

Use:

  1. Enter copy mode: Ctrl+b [
  2. Position cursor at top-left of target area
  3. Press r to enable rectangle selection
  4. Move to bottom-right
  5. Press y to copy

Practical Copy Workflow for Logs

Scenario: copy an error message from a log tail

1. In a pane showing: tail -f /var/log/app.log
2. Press Ctrl+b [ → freeze view, enter copy mode
3. Press G → jump to latest output
4. Navigate to error line
5. Press v → start selection
6. Press $ → line end (or extend with j for multiple lines)
7. Press y → copy
8. Press Ctrl+b ] → paste wherever you need it

Common Pitfalls

PitfallSymptomFix
Pasting overwrites instead of insertingPasted text replaces content in editorPosition cursor correctly before pasting
Tmux buffer vs system clipboard confusionWrong content pastedKnow which buffer you are using
Copy mode freezes the pane"Nothing is updating"You are in copy mode — press q to exit

What's Next