6

I set up tmux in WSL and I want to improve the integration between them.

How to select text in tmux inside of WSL and copy it to the Windows clipboard?

2 Answers 2

15
  • open the file ~/.tmux.conf and create it if it does not exist
  • enable mouse mode by adding the line set -g mouse on (if not, you will have to select the text with Ctl+[)
  • create a key binding to copy the tmux buffer to the windows clipboard:

    bind -n M-w run -b "tmux show-buffer | clip.exe"

With this key configuration, you can select text with the mouse and copy it(to the tmux buffer) using Alt+w. (If you want to select something and don't want it to disappear, press shift while letting the mouse button go.) After this, press Alt+w again in order to copy the tmux buffer to the Windows clipboard.

1
  • -bash: clip.exe: command not found
    – quant
    Commented Jul 9, 2022 at 5:23
9

EDIT: After numerous issues about clipboard in windows terminal being opened and closed, it seems to be sufficient to set set-option -g mouse on in ~/tmux.conf to have working "copy on select" these days.

Old answer: Alternatively, if you are using windows terminal, selecting text with the mouse while holding shift and copying it with Ctl + Insert will always just work (even through ssh) and doesn't mess up line breaks.

4
  • 1
    This just works! Thanks! Commented Aug 5, 2020 at 21:38
  • Yes, but doesn't work when you have multiple panes open in Tmux, as the selection just goes across all Tmux panes. So, not a solution. Commented Jul 15 at 16:15
  • @fourpastmidnight hmset-option -g mouse on in tmux seems to be enough to be able to copy text to windows by simply selecting it with the left mouse in tmux over ssh in windows terminal these days (windows terminal 1.20.11781.0)
    – jan-glx
    Commented Jul 15 at 19:34
  • Yup. There's a lot of old information out there, unfortunately. I found the same to be true. Thanks @jan-glx ! Commented Jul 15 at 21:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .