PQ
PQ.Hosting

Currency

Copy and Paste in tmux: vi Mode, System Clipboard, and xclip

Author
PQ
March 18, 2026
4 min read
86 views
Copy and Paste in tmux: vi Mode, System Clipboard, and xclip

The tmux clipboard lives separately from the system clipboard. Copy something inside tmux — it will not paste into a browser. Copy in a browser — it will not paste into tmux. Understanding this separation and configuring the bridge between them is everything you need to know about copying in tmux.

How tmux Copying Works

tmux has its own internal paste buffer — completely separate from the X11 clipboard and macOS system clipboard. Text enters it through copy-mode, and only explicit configuration allows syncing with the system clipboard.

By default copy-mode uses emacs keybindings. Most people prefer vi mode — one line in .tmux.conf:

set-window-option -g mode-keys vi

Apply without restarting:

Ctrl+b  :source-file ~/.tmux.conf

Enter Copy Mode

Ctrl+b  [

In copy-mode the cursor becomes active — you can scroll through terminal output. Arrow keys always work. In vi mode full navigation is available.

Navigation in Copy Mode (vi Mode)

Key Action
h j k l Movement like vim
w / b Word forward / backward
f + char Jump to character in line
G End of output
g Beginning of output
Ctrl+d Half screen down
Ctrl+u Half screen up
/ + text Search forward
? + text Search backward
n / N Next / previous match

Select and Copy Text (vi Mode)

Start selection:

Space

Move the cursor to the end of the desired fragment. Copy to the tmux buffer:

Enter

copy-mode closes automatically after Enter — the text is in the tmux buffer.

Rectangular selection (column block):

Ctrl+v

Then select with arrow keys, then Enter.

Paste From the tmux Buffer

Paste the last copied fragment into the current pane:

Ctrl+b  ]

Multiple Buffers: Copy History

tmux stores a history of all copied fragments. List them:

Ctrl+b  #

Or from the command line:

tmux list-buffers

Show the content of the last buffer:

tmux show-buffer

Paste from a specific buffer by number:

tmux paste-buffer -b 2

Save buffer to a file:

tmux save-buffer /tmp/tmux-clipboard.txt

Sync With System Clipboard: Linux (X11)

By default text copied in tmux does not reach the X11 clipboard. Configure automatic sync — add to ~/.tmux.conf:

bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "xclip -selection clipboard -i"

Or via xsel:

bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "xsel --clipboard --input"

Install xclip:

sudo apt install xclip

After this, Enter in copy-mode copies text to both the tmux buffer and the system clipboard simultaneously.

Sync With System Clipboard: macOS

On macOS use pbcopy instead of xclip:

bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "pbcopy"

Mouse Mode: Select by Clicking

Enable mouse support:

set -g mouse on

After this, selecting text with the mouse automatically enters copy-mode. Release the button — the text is in the tmux buffer.

Note: with mouse enabled, terminal scrolling is intercepted by tmux. If this interferes — hold Shift while selecting to bypass tmux and use the terminal emulator's native selection.

Paste External Text Into tmux

Copied something outside (browser, editor) — paste into tmux.

On Linux:

Shift+Insert

Or the terminal emulator's paste shortcut — Ctrl+Shift+V in most terminals.

On macOS in iTerm2 or Terminal:

Cmd+V

Ready-Made ~/.tmux.conf for Comfortable Copying

set-window-option -g mode-keys vi
set -g mouse on

bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "xclip -selection clipboard -i"
bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "xclip -selection clipboard -i"
bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "xclip -selection clipboard -i"

What this does: v starts selection like in vim, y copies without exiting copy-mode, Enter copies and exits, mouse drag selection also sends to the system clipboard.

For macOS replace xclip -selection clipboard -i with pbcopy.

Quick Reference

Task Keys / Command
Enter copy-mode Ctrl+b [
Start selection (vi) Space
Copy selection Enter
Rectangular selection Ctrl+v → select → Enter
Paste from tmux buffer Ctrl+b ]
List buffers tmux list-buffers
Show last buffer content tmux show-buffer
Save buffer to file tmux save-buffer /tmp/out.txt
Paste from buffer #2 tmux paste-buffer -b 2
Exit copy-mode q
Search in copy-mode /text

Share this article