With xclip, mouse and copy/paste can work over SSH-forwarded X-sessions with C-y and Enter from copy-mode-vi so:
# For older versions of tmux:
#setw -g mode-mouse on
#set -g mouse-resize-pane on
#set -g mouse-select-pane on
#set -g mouse-select-window on
# For newer versions of tmux:
set -g mouse on
bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'select-pane -t=; copy-mode -e; #send-keys -M'"
bind -n WheelDownPane select-pane -t= \; send-keys -M
set -g set-clipboard on
# With xclip
bind-key -n C-y run "tmux show-buffer | xclip -selection clipboard -i >/dev/null"
#bind-key -n C-y run-shell "tmux save-buffer - | xclip -i -selection clipboard >/dev/null"
# For tmux 2.4+
bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel 'xclip -selection clipboard -i'
For Windows vcxsrv is the simplest and most fool-proof X-Windows server. Anything else on Windows may result in pain.My preference is to reduce visual clutter in tmux by tweaking config and mostly just follow built-in bindings so workflow mostly works on standard tmux as well.
When clipboard fails between environments, sometimes multiple copy-ing, and then pasting into a text-editor helps (not a tmux issue, but clipboard-integrations).
X servers on Windows are often a bigger cut/paste barrier than tmux. As you mention, vcxsrv seems to work better than other choices. Note there are some cut/paste/clipboard options you have to set.
<?xml version="1.0" encoding="UTF-8"?>
<XLaunch WindowMode="MultiWindow" ClientMode="NoClient" LocalClient="False" Display="0" LocalProgram="xcalc" RemoteProgram="xterm" RemotePassword="" PrivateKey="" RemoteHost="" RemoteUser="" XDMCPHost="" XDMCPBroadcast="False" XDMCPIndirect="False" Clipboard="True" ClipboardPrimary="True" ExtraParams="" Wgl="True" DisableAC="False" XDMCPTerminate="False"/> # For tmux 2.6+
set -s set-clipboard externalhttps://github.com/tmux-plugins/tmux-copycat
The other change is to use vi keys for highlight mode:
# set highlight mode keys
setw -g mode-keys vi
bind Escape copy-mode bind-key P command-prompt -p 'save history to filename:' -I '~/tmux.history' 'capture-pane -S -32768 ; save-buffer %1 ; delete-buffer'
then it's all in a file you can work with in an editor of your choiceC-Space marks a region, move arrows to select text, and M-w to copy to clipboard.
q to escape copy mode
This seems to be to the tmux's own clipboard. When you want to copy externally many lines, you can use C-b Z to zoom or use a lame workaround with text files opened in gedit or something. (It's a marginal use case in my experience, so I didn't bother to optimize.)
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'
Works just like vim. Press v to go into visual mode, then y to yank the selection#makes clipboard work
set-option -g default-command "reattach-to-user-namespace -l fish"
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"
bind -Tcopy-mode-vi MouseDragEnd1Pane copy-pipe-and-cancel "if [ \"$(uname)\" = 'Darwin' ]; then pbcopy; else xclip; fi"
to achieve the same thing. It also looks like you can configure copy commands to pipe to a command of your choice with the upcoming version of tmux without having to override keybindings [3].[1]: >= 2.4, maybe?
[2]: Any terminal that supports OSC52 (e.g, iTerm2)
[3]: https://github.com/tmux/tmux/commit/5aba26f2cb7aa9609a3c3d2b...
If formatting is super important, I paste into a file with cat > file, and read the file into Emacs. I can do the same in reverse for a big copy out, and transfer the file.
I do these things because I often use Emacs in a ssh session instead of tramp, because I'm coming from a different OS or need to use modes with sidecar executables, e.g. enh-ruby-mode.