Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sahensley/a985b102b1e8f3eafe8cab84a3aacc79 to your computer and use it in GitHub Desktop.
Save sahensley/a985b102b1e8f3eafe8cab84a3aacc79 to your computer and use it in GitHub Desktop.
Tmux config to copy to the Windows system clipboard

About

Tmux 2.4 (April 2017) added a very useful copy-pipe-and-cancel command.

The config below configures copying to the tmux buffer and the Windows system clipboard in one command, including click-and-drag copying (without holding shift). I'm sure there's a way to get this to work with copy-mode (emacs style) but I'm not familiar enough with it to offer any advice. I've tested the config successfully both in WSL via PowerShell and WSL via MinTTY.

Config

# Configure copying
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi Escape send-keys -X cancel
bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "/mnt/c/Windows/System32/clip.exe"
bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "/mnt/c/Windows/System32/clip.exe"
bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "/mnt/c/Windows/System32/clip.exe"
@mpawelski
Copy link

Thanks a lot. This helped me a lot to configure if with copy-mode

If someone already learned default key bindings of tmux (https://unix.stackexchange.com/a/58765/200236) and just want to have mouse support plus copying to windows clipboard then this is my .tmux.conf

set-option -g mouse on
bind-key -T copy-mode C-w send-keys -X copy-pipe-and-cancel "/mnt/c/Windows/System32/clip.exe"
bind-key -T copy-mode MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "/mnt/c/Windows/System32/clip.exe"

@sahensley
Copy link
Author

I was surprised by the lack of information available, glad my post was of some help. Thanks for the default key binding additions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment