How to configure clipboard integration in tmux?

Quick Answer

Add set-option -g set-clipboard external to your ~/.tmux.conf to enable automatic clipboard synchronization. When you copy text in tmux copy mode, it will automatically be available in your system clipboard.

set-option -g set-clipboard external

Detailed Explanation

Tmux clipboard integration allows text copied in copy mode to automatically sync with your system clipboard. This eliminates the need to manually copy text outside of tmux and makes it available to other applications.

Basic Setup

# In ~/.tmux.conf
set-option -g set-clipboard external  # Recommended
set-option -g mouse on                 # Enable mouse selection
set-window-option -g mode-keys vi      # Vi-style copy mode

Enhanced Copy Mode Bindings

Add these bindings for better copy mode experience:

# Vi-style copy bindings
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 'pbcopy'  # macOS
bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel 'pbcopy'

Platform-Specific Commands

Replace pbcopy with your platform's clipboard command:

# macOS: pbcopy
# Linux with X11: xclip -selection clipboard
# Linux with Wayland: wl-copy  
# Windows/WSL: clip.exe

Usage

Enter copy mode with Ctrl+b [, select text with v, and copy with y. The text will be available in your system clipboard.

Pro Tip

With mouse support enabled, you can also select text with your mouse and it will automatically copy to the system clipboard when you release the mouse button.

OSC 52 Support

For SSH sessions, ensure your terminal supports OSC 52 escape sequences:

set-option -g allow-passthrough on
set-option -g terminal-features 'xterm*:clipboard'