(scroll to the bottom to skip the explanation and see how to copy/paste to/from the desktop clipboard.)
Tmux is agnostic to the window system/terminal emulator used. It simply runs in text mode using the
$TERM environment variable to look up the terminal capabilities (using terminfo(5)) and then just interacts with the (pseudo-)TTY.
The mouse mode is implemented by requesting the TTY to translate mouse clicks and movements to various escape sequences and feed them to the
tmux program (whether this is possible or not depends on the terminfo(5) information for the terminal emulator). Tmux will read and interpret these “mouse escape sequences”, and do the highlighting and copying of the selected text. Since it is oblivious to any GUI or windowing system (see above), it will not automatically copy the text to any other clipboard than its own internal one.
However, it is possible to tell
tmux to copy the text to the clipboard, by using some configuration magic and a CLI tool like
xsel (don’t use
xclip, it seems to have issues).
# TMUX configuration for copying selection buffer to the (X11) clipboard.
# Copy mouse selection tmux buffer AND to (X11) clipboard
bind-key -Tcopy-mode-vi MouseDragEnd1Pane send -X copy-pipe-and-cancel "xsel -i --clipboard"
# Copy tmux buffer to the (X11) clipboard.
bind-key C-c run "tmux save-buffer - | xsel -i --clipboard"
# Copy (X11) clipboard to tmux buffer and paste in current pane.
bind-key C-v run "xsel -o --clipboard 2>/dev/null | tmux load-buffer - && tmux paste-buffer"
# Only in tmux 1.8 and higher. Copy selection will set (X11) clipboard as well.
bind-key -Tcopy-mode-vi Enter send -X copy-pipe-and-cancel "xsel -i --clipboard"
The above text was copied selected in a
tmux window and pasted here with Ctrl+V.