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
| Method | How | Paste with |
|---|---|---|
| Tmux buffer (copy mode) | Ctrl+b [ → select → y | Ctrl+b ] |
| Terminal native | Hold Shift + click/drag | Mouse middle-click or terminal paste |
| System clipboard | Copy mode → pipe to xclip/pbcopy | OS paste (Ctrl+V or middle-click) |
Method 1: Tmux Buffer (Standard)
- Enter copy mode
- Navigate to text using vim keys (h j k l / g G)
- Press
vto start selection - Move to end of selection
- Press
yto copy and exit - Paste from buffer
| Default Shortcut | Modification Shortcut | Action |
|---|---|---|
Ctrl+b [ | Ctrl+Space [ | Enter copy mode |
Ctrl+b ] | Ctrl+Space ] | 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+clickand drag, thenCtrl+Shift+C(or terminal-specific) - Paste:
Ctrl+Shift+Vor 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
| Default Shortcut | Modification Shortcut | Action |
|---|---|---|
Ctrl+b = | Ctrl+Space = | Choose paste buffer interactively |
# 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
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:
- Enter copy mode:
Ctrl+b [ - Position cursor at top-left of target area
- Press
rto enable rectangle selection - Move to bottom-right
- Press
yto copy
Practical Copy Workflow for Logs
Scenario: copy an error message from a log tail
- In a pane showing:
tail -f /var/log/app.log - Enter copy mode with
Ctrl+b [ - Press
Gto jump to latest output - Navigate to error line
- Press
vto start selection - Press
$for line end (or extend withjfor multiple lines) - Press
yto copy - Paste with
Ctrl+b ]
| Default Shortcut | Modification Shortcut | Action |
|---|---|---|
Ctrl+b [ | Ctrl+Space [ | Enter copy mode (freeze view) |
Ctrl+b ] | Ctrl+Space ] | Paste from buffer |
Common Pitfalls
| Pitfall | Symptom | Fix |
|---|---|---|
| Pasting overwrites instead of inserting | Pasted text replaces content in editor | Position cursor correctly before pasting |
| Tmux buffer vs system clipboard confusion | Wrong content pasted | Know which buffer you are using |
| Copy mode freezes the pane | "Nothing is updating" | You are in copy mode — press q to exit |