Copy and Paste From Tmux in Wayland

Copy-pasting between tmux and Linux desktop feels clunky, because they use separate clipboards by default. Here’s how to merge them into one in Wayland, giving you consistent behavior and more pleasant experience.

Pre-requisites

Before you start configuring tmux, you need these thing ready:

Configuration

To enable copy-pasting using system clipboard, add these settings to your tmux configuration file. It is typically stored in ~/.config/tmux/tmux.conf or ~/.tmux.conf.

These bindings also make tmux copy mode behave more like Vim’s.

# Turn off internal tmux buffer and use the system one
set-option -sg set-clipboard off

# Vi-like copy selection to system clipboard
bind -T copy-mode-vi v send-keys -X begin-selection
bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel 'wl-copy'

# Change Enter to use system clipboard as well
unbind -T copy-mode-vi Enter
bind -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel 'wl-copy'

# Vi-like paste
bind P paste-buffer

Voila — tmux now uses the system clipboard. For a more detailed description of the individual options, refer to tmux manual.

Test it

  1. Press <Ctrl-b> [ to enter copy‑mode in tmux.
  2. Select text with vhjkl.
  3. Press y.
  4. Switch to any GUI app and paste with Ctrl‑V. You should see the exact same text.

Conclusion

Configuring tmux to use the system clipboard makes copy-paste far smoother. Hopefully, this will become the default behavior one day.