jasoncarloscox.com/creations/vim-wayland-clipboard
This plugin allows Vim to integrate with the Wayland clipboard when using the +
register. This means you can yank text into the +
register and paste it in other Wayland programs, or copy text in other Wayland programs and paste it in Vim from the +
register. Operators and counts work, too!
When running Vim outside of Wayland, the +
register continues to work as normal.
For this plugin to work, you need wl-clipboard installed, and Vim must be compiled with the +eval
feature.
Use Vim8's built-in packages:
mkdir -p ~/.vim/pack/vim-wayland-clipboard/start/
git clone https://github.com/jasonccox/vim-wayland-clipboard.git ~/.vim/pack/vim-wayland-clipboard/start/vim-wayland-clipboard
Just use "+y
, "+p
, <C-R>+
, and friends as you always do. Specifically, here's what's supported:
- Any yank command that starts with
"+
(e.g."+yy
or"+yiw
) in insert and visual modes. - Pasting in normal and visual modes with
"+p
or"+P
. - Pasting in insert mode with
<C-R>+
,<C-R><C-R>+
,<C-R><C-O>+
, or<C-R><C-P>+
. - Yanking and pasting (
p
andP
in normal and visual modes) withclipboard=unnamedplus
.
If you need more functionality, consider checking out vim-fakeclip.
If you want to pass extra arguments to wl-copy
, set g:wayland_clipboard_copy_args
to a list of strings, one per argument. For example, to copy to the primary clipboard and only allow the contents to be pasted once, you could do the following:
let g:wayland_clipboard_copy_args = ['--primary', '--paste-once']
To pass extra arguments to wl-paste
, use g:wayland_clipboard_paste_args
in the same way.
On Vim builds without clipboard
, or if Xwayland isn't running, the +
register doesn't work for yanking. My solution is to map "+
to "w
and send the w
register to the Wayland clipboard as well. (This only occurs when the clipboard
feature is missing or the X $DISPLAY
environment vairable is empty.) If you use the w
register for other things and don't want it to clobber your system clipboard, put let g:wayland_clipboard_no_plus_to_w = 1
in your vimrc
to disable this feature.
This plugin uses mappings of "+p
, <C-R>+
, "+
, etc. to do its job. As a result, it won't work with existing non-recursive mappings that run these commands, e.g. nnoremap <Leader>p "+p
. If you have mappings like these, you'll need to use their recursive counterparts instead for the plugin to work.
Contributions are welcome! You can send questions, bug reports, patches, etc. by email to ~jcc/public-inbox@lists.sr.ht. (Don't know how to contribute via email? Check out the interactive tutorial at git-send-email.io, or email me for help.)
GitHub issues and pull requests are fine, too.