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

前端 未结 6 1138
天涯浪人
天涯浪人 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 04:55

    Building off of @ideasman42 's answer. This is using tmux 2.8 and pbcopy for macos mojave.

    # Double LMB Select & Copy (Word)
    bind-key -n DoubleClick1Pane \
        select-pane \; \
        copy-mode -M \; \
        send-keys -X select-word \; \
        run-shell "sleep .5s" \; \
        send-keys -X copy-pipe-and-cancel "pbcopy"
    bind-key -n DoubleClick1Pane \
        select-pane \; \
        copy-mode -M \; \
        send-keys -X select-word \; \
        run-shell "sleep .5s" \;
        send-keys -X copy-pipe-and-cancel "pbcopy
    

    My version selects the word, briefly highlights it, copies it to the system buffer and then cancels copy-mode.

    0 讨论(0)
  • 2021-02-01 04:57

    Don't know about iterm2, but this can be made to work in tmux 3.0 or newer
    (tested on Linux w/ tmux 3.0, last command uses X11 xclip).

    Added triple click to select and copy a line too.

    # Double LMB Select & Copy (Word)
    bind-key -T copy-mode-vi DoubleClick1Pane \
        select-pane \; \
        send-keys -X select-word-no-clear \; \
        send-keys -X copy-pipe-no-clear "xclip -in -sel primary"
    bind-key -n DoubleClick1Pane \
        select-pane \; \
        copy-mode -M \; \
        send-keys -X select-word \; \
        send-keys -X copy-pipe-no-clear "xclip -in -sel primary"
    
    # Triple LMB Select & Copy (Line)
    bind-key -T copy-mode-vi TripleClick1Pane \
        select-pane \; \
        send-keys -X select-line \; \
        send-keys -X copy-pipe-no-clear "xclip -in -sel primary"
    bind-key -n TripleClick1Pane \
        select-pane \; \
        copy-mode -M \; \
        send-keys -X select-line \; \
        send-keys -X copy-pipe-no-clear "xclip -in -sel primary"
    

    If you don't use copy-mode-vi, replace this with copy-mode.


    For older tmux versions check the edit-history.

    0 讨论(0)
  • 2021-02-01 04:57

    In Alacrity holding Shift allows copying as if there's no tmux.

    source

    0 讨论(0)
  • 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
    0 讨论(0)
  • 2021-02-01 05:02

    On Kitty/Alacritty, we double-click on the text-block while keeping Shift pressed. And copying works fine natively as well as within tmux.

    0 讨论(0)
  • 2021-02-01 05:11

    I found a way to achieve that: hold the option key when double clicking.

    0 讨论(0)
提交回复
热议问题