From 3e9dcaff9da467d02f31b1a1381d29350a37997c Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Fri, 18 Oct 2024 15:27:56 +0200 Subject: [PATCH] tmux: Paste primary selection with middle mouse Similar to everywhere else, paste the primary X selection (XA_PRIMARY) instead of the most recent tmux paste buffer. TODO: Forward event to 'root' key-table to prevent code duplication --- .config/tmux/tmux.conf | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.config/tmux/tmux.conf b/.config/tmux/tmux.conf index b42a026..cd99f61 100644 --- a/.config/tmux/tmux.conf +++ b/.config/tmux/tmux.conf @@ -69,6 +69,25 @@ bind -n TripleClick1Pane { } } +# Paste primary selection with middle mouse button +bind -n MouseDown2Pane { + select-pane -t= + if -F "#{||:#{pane_in_mode},#{mouse_any_flag}}" { + send -M + } { + run 'tmux set-buffer -b XA_PRIMARY "$(xclip -selection p -o)"' + paste-buffer -p -b XA_PRIMARY + } +} +# When in copy-mode do the same but leave copy-mode first +bind -T copy-mode-vi MouseDown2Pane { + select-pane -t= + send -X cancel + # TODO: Forward click to 'root' key-table to prevent code duplication + run 'tmux set-buffer -b XA_PRIMARY "$(xclip -selection p -o)"' + paste-buffer -p -b XA_PRIMARY +} + # Scroll up 5 lines when entering copy-mode through the mouse wheel, send 5x`up` # when the current pane is in alternate mode and discard the `-e` flag passed to # copy-mode from the default binding (See below)