tmux supports bidirectional clipboard integration with the host system using the OSC 52 escape sequence. This allows copying from tmux to the system clipboard and pasting from the system clipboard into tmux.
From window-copy.c:5034-5080, the copy-pipe command copies selection and pipes to external command:
# Copy to system clipboard with external commandbind -T copy-mode-vi y send -X copy-pipe-and-cancel "xclip -selection clipboard"# On macOSbind -T copy-mode-vi y send -X copy-pipe-and-cancel "pbcopy"# On Waylandbind -T copy-mode-vi y send -X copy-pipe-and-cancel "wl-copy"
Default bindings from key-bindings.c:456-459:
# Double-click word selectionbind -n DoubleClick1Pane { select-pane -t= if -F '#{||:#{pane_in_mode},#{mouse_any_flag}}' { send -M } { copy-mode -H send -X select-word run -d0.3 send -X copy-pipe-and-cancel }}# Triple-click line selectionbind -n TripleClick1Pane { select-pane -t= if -F '#{||:#{pane_in_mode},#{mouse_any_flag}}' { send -M } { copy-mode -H send -X select-line run -d0.3 send -X copy-pipe-and-cancel }}
From options-table.c:411-420, control how tmux responds to clipboard requests:
static const char *options_table_get_clipboard_list[] = { "off", // Ignore requests "buffer", // Return tmux buffer content "request", // Request from terminal "both", // Try request, fall back to buffer NULL};
Configuration
# Application requests clipboard - try terminal first, fall back to bufferset -g get-clipboard both# Only use terminal clipboardset -g get-clipboard request# Only use tmux buffersset -g get-clipboard buffer
# Copy to X clipboardbind -T copy-mode-vi y send -X copy-pipe-and-cancel "xclip -selection clipboard -i"# Alternative: xselbind -T copy-mode-vi y send -X copy-pipe-and-cancel "xsel --clipboard --input"# Paste from X clipboardbind p run "tmux set-buffer \"$(xclip -selection clipboard -o)\"; tmux paste-buffer"
~/.tmux.conf
# Copy to Wayland clipboardbind -T copy-mode-vi y send -X copy-pipe-and-cancel "wl-copy"# Paste from Wayland clipboard bind p run "tmux set-buffer \"$(wl-paste)\"; tmux paste-buffer"
~/.tmux.conf
# Copy to macOS clipboardbind -T copy-mode-vi y send -X copy-pipe-and-cancel "pbcopy"# Paste from macOS clipboardbind p run "tmux set-buffer \"$(pbpaste)\"; tmux paste-buffer"# Enable native macOS clipboard (no OSC 52 needed)set -g set-clipboard on
~/.tmux.conf
# Copy to Windows clipboard from WSLbind -T copy-mode-vi y send -X copy-pipe-and-cancel "clip.exe"# Paste from Windows clipboardbind p run "tmux set-buffer \"$(powershell.exe Get-Clipboard)\"; tmux paste-buffer"
#!/bin/sh# Continuously sync tmux and system clipboardwhile true; do # Get tmux buffer tmux_buf=$(tmux save-buffer - 2>/dev/null) # Get system clipboard sys_clip=$(xclip -selection clipboard -o 2>/dev/null) # Sync if different if [ "$tmux_buf" != "$sys_clip" ]; then if [ -n "$sys_clip" ]; then tmux set-buffer "$sys_clip" fi fi sleep 1done
# Save all copies to history with timestampbind -T copy-mode-vi y send -X copy-pipe-and-cancel ' tee -a ~/.clipboard-history | \ awk "{print \"[\" strftime(\"%Y-%m-%d %H:%M:%S\") \"] \" \$0}" >> ~/.clipboard-log; \ xclip -selection clipboard -i'# Browse clipboard historybind P run "cat ~/.clipboard-history | fzf | tmux load-buffer -; tmux paste-buffer"