vim-yoink
vim-yoink copied to clipboard
Implement basic sync with Wayland clipboard
Having switched to Wayland / Sway a short while ago, I've found working with the system clipboard and vim somewhat frustrating. After fiddling a lot with the "usual" recommendations to remap things like "+y
without finding any satisfying solution, I discovered vim-yoink and found it to be a great reason to replace the ancient YankRing.
At some point, I realized I could leverage yoink's clipboard synchronization to solve all (well most ;) of my problems.
This (very basic and possibly horrible – I know little about writing "good Vimscript") PR is what I've come up with: Basically it adds a config option g:yoinkUseWlClipboard
, and if that is set and wl-copy
and wl-paste
are available (from https://github.com/bugaevc/wl-clipboard), it sets the defaultReg
to the system clipboard's content (if it is different from the current default clipboard register content) in yoink#onFocusGained()
.
The according opposite action is sending the yanked content to the system clipboard in yoink#onYank
.
From some cursory testing, this breaks nothing I could observe and also seems to function as it should when using vim-submersive together with vim-yoink.
It should be noted that this PR somewhat intentionally ignores the 'primary' system clipboard/buffer (for selected text and middle mouse click behaviour), but this could be added by calling wl-copy
and wl-paste
with --primary
.
I have also not yet tried to see what happens if the clipboard's content is of a different mime type (eg. an image).
/edit
Addressing the last point: well, it inserts it (an image) pretty much raw. So… at least nothing breaks ^^
I've changed the PR to use a more generalized approach. With this, it's less Wayland-focused but instead user specified clipboard commands can be provided.
Now to achieve syncing with the Wayland system clipboard via wl-clipboard, one could provide
let g:yoinkSystemPasteCmd = "wl-paste --no-newline"
let g:yoinkSystemYankCmd = "wl-copy --type text/plain"
and those commands would be invoked.
I've observed one potential issue in the meantime: for some reason, when deleting (instead of just yanking) and then pasting afterwards, it sometimes seems to hang. I'm not yet certain where this is coming from (vim? yoink? wl-clipboard? wayland? sway?) – so I'll still keep this as a draft PR for now.