Can I use double click to select and copy in tmux?

前端 未结 6 1141
天涯浪人
天涯浪人 2021-02-01 04:04

I am learning to use tmux, I found when I in a tmux window, double-click to select and copy function did not work any more.

Can I use double-click to select and copy jus

6条回答
  •  不思量自难忘°
    2021-02-01 05:00

    I have figured out a copy paste mechanism that is similar of what you will expect form a terminal

    I used the following settings to be able to:

    1. select a word with a mouse double click action
    2. select a line with a mouse tripple click action
    3. select a partial line a mouse drag and drop action

    This solution will keep the selection highlighted and copy the selection output to both clipboard buffers (primary and clipboard)

    When you hit "Enter" you exit and go back to the shell

    The advantage here is that you can use both middle mouse button as shift-insert combination outside of tmux to paste the content, while it is still selected.

    Also when you exited back to the shell, you can use middle mouse button or hit shift-insert to paste the content

    All what you would expect from a normal terminal environment

        # Enable mouse control
        setw -g mouse on
    
        unbind -T copy-mode-vi Enter
        bind-key -T copy-mode-vi Enter \
            send -X cancel
    
        # Drag and Drop Aelect & Copy (Selection)
        bind-key -T copy-mode-vi MouseDragEnd1Pane \
            send-keys -X copy-pipe "xclip -in -f | xclip -in -sel c" \; \
            send-keys -X no-clear
    
        # Double LMB Select & Copy (Word)
        bind-key -T copy-mode-vi DoubleClick1Pane \
            select-pane \; \
            send-keys -X select-word \; \
            send-keys -X copy-pipe "xclip -in -f | xclip -in -sel c" \; \
            send-keys -X no-clear
        bind-key -n DoubleClick1Pane \
            select-pane \; \
            copy-mode -M \; \
            send-keys -X select-word \; \
            send-keys -X copy-pipe "xclip -in -f | xclip -in -sel c" \; \
            send-keys -X no-clear
    
        # Triple LMB Select & Copy (Line)
        bind-key -T copy-mode-vi TripleClick1Pane \
            select-pane \; \
            send-keys -X select-line \; \
            send-keys -X copy-pipe "xclip -in -f | xclip -in -sel c" \; \
            send-keys -X no-clear
        bind-key -n TripleClick1Pane \
            select-pane \; \
            copy-mode -M \; \
            send-keys -X select-line \; \
            send-keys -X copy-pipe "xclip -in -f | xclip -in -sel c" \; \
            send-keys -X no-clear
    
        # Middle click to paste from the primary buffer
        unbind-key MouseDown2Pane
        bind-key -n MouseDown2Pane run "tmux set-buffer \"$(xclip -o)\"; tmux paste-buffer"
    
        # Shift insert to paste from the clipboard
        unbind-key S-IC
        bind-key S-IC run "tmux set-buffer \"$(xclip -o -sel c)\"; tmux paste-buffer"
    
    • NOTE1 : in order for this to work across a ssh session : -X has to be provided as option to ssh
    • NOTE2: I'm using tmux version 2.8

提交回复
热议问题