Copying from a remote tmux pane to your laptop's clipboard is a daily need that tmux does not do out of the box everywhere.
tmux copies into its own paste buffers. There are two ways to also reach the system clipboard.
OSC 52. Terminals that support the OSC 52 escape sequence (iTerm2, kitty, WezTerm, Alacritty, Windows Terminal, recent GNOME terminals...) let a program set the clipboard by printing a sequence. tmux's set-clipboard option controls this: the default external forwards copies to the terminal, on additionally lets programs inside tmux set the clipboard. The great property is that it works over SSH: a tmux on a server can put text on your laptop's clipboard, because the sequence travels through the terminal. Some terminals require enabling it, and tmux must know the terminal supports it (the clipboard terminal feature, usually detected automatically).
copy-pipe. Alternatively, bind copy keys to pipe the selection to a command: copy-pipe-and-cancel 'pbcopy' on macOS, 'xclip -selection clipboard' on X11 or 'wl-copy' on Wayland. This only works where tmux runs on the same machine as your desktop. The copy-command option sets a default command for all copy-pipe actions.
Typical vi-style bindings: v to begin selection, y to copy. Test OSC 52 with printf '\033]52;c;%s\a' "$(printf hi | base64)" in a pane; if "hi" is on your clipboard, your terminal supports it.
Example
# ~/.tmux.conf
setw -g mode-keys vi
set -g set-clipboard on # use OSC 52 (works over SSH)
bind -T copy-mode-vi v send -X begin-selection
bind -T copy-mode-vi y send -X copy-selection-and-cancel
# local alternative: pipe to a clipboard tool
# set -s copy-command 'wl-copy' # or 'pbcopy', 'xclip -selection clipboard'
# bind -T copy-mode-vi y send -X copy-pipe-and-cancel
# shell test for OSC 52 support:
printf '\033]52;c;%s\a' "$(printf hi | base64)"Remember
- set-clipboard + OSC 52 lets the terminal own the clipboard, even over SSH
- copy-pipe sends the selection to pbcopy/xclip/wl-copy on the same machine
- bind -T copy-mode-vi ... send -X customises copy keys
Watch out for
- Using xclip in a tmux on a remote server and expecting your laptop clipboard to change; use OSC 52 instead.