To copy text to the system clipboard in tmux, you need to configure tmux to integrate with your system clipboard. This typically involves entering copy mode (Ctrl+b [
), selecting text, and using a modified copy command that pipes to your system's clipboard utility.
By default, tmux only copies text to its internal buffer, not to your system clipboard. To enable system clipboard integration, you need to add specific configuration to your tmux.conf file and possibly install additional utilities.
brew install reattach-to-user-namespace
sudo apt install xclip
or sudo apt install xsel
sudo apt install xclip
and ensure Windows clipboard integrationAdd these lines to your ~/.tmux.conf
file:
# For macOS
set-option -g default-command "reattach-to-user-namespace -l $SHELL" # Enable vi mode set-window-option -g mode-keys vi # Setup 'v' to begin selection, 'y' to copy to system clipboard bind-key -T copy-mode-vi 'v' send -X begin-selection bind-key -T copy-mode-vi 'y' send -X copy-pipe-and-cancel 'reattach-to-user-namespace pbcopy'
# For Linux with xclip
set-window-option -g mode-keys vi bind-key -T copy-mode-vi 'v' send -X begin-selection bind-key -T copy-mode-vi 'y' send -X copy-pipe-and-cancel 'xclip -in -selection clipboard'
Ctrl+b [
to enter copy modev
to start selection (if using vi mode)y
to copy to system clipboardFor easier copying, enable mouse mode and configure it to copy to clipboard:
# Enable mouse mode set -g mouse on # For macOS: Copy mouse selection to clipboard bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "pbcopy" # For Linux: Copy mouse selection to clipboard bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "xclip -in -selection clipboard"