Background
I use wayland and neovim and when pasting external text it would add ^M
to the end of each line. This is a known "bug" (https://github.com/neovim/neovim/issues/10223) and there exists a workaround: Using sed to trim the ^M
:
let g:clipboard = {
\ 'name': 'WL-Clipboard with ^M Trim',
\ 'copy': {
\ '+': 'wl-copy --foreground --type text/plain',
\ '*': 'wl-copy --foreground --type text/plain --primary',
\ },
\ 'paste': {
\ '+': {-> systemlist('wl-paste --no-newline | sed -e "s/\r$//"')},
\ '*': {-> systemlist('wl-paste --no-newline --primary | sed -e "s/\r$//"')},
\ },
\ 'cache_enabled': 1,
\ }
Neovim defaults to wl-paste
on my system, when g:clipboard
is not set.
Problem
With the workaround in place, neovim does not paste linewise copies in a newline.
Expected Behaviour: Go to a line -> press
Y
-> go to the middle of another line -> pressp
-> The copied line is pasted in a new line. This is what happens when nog:clipboard
is set.Observed Behaviour: Go to a line -> press
Y
-> go to the middle of another line -> pressp
-> The copied line is pasted into the current line. This is what happens wheng:clipboard
is set.
When observing the content of the wayland clipboard, (wl-paste --no-newline | cat -A
) they are the same. Both end with a LF character.
Question:
Why is this? What does neovim do to distinguish between a paste into a new line and why does neovim not paste into a new line when having the custom g:clipboard
in place?