[vim/vim] Copy/paste operations between different instances on Wayland doesn't work correctly (#7922)

204 views
Skip to first unread message

Bogdan

unread,
Mar 2, 2021, 12:02:04 PM3/2/21
to vim/vim, Subscribed

I have a problem on copying text between different instances of Vim on Wayland (exactly I use Sway window system). Natively it's not supported, because Wayland doesn't have a clipboard itself. But it can be installed. Following the instructions from several sources in internet I did the next steps:
1)Install package wl-clipboard.
2)Modify ~/.vimrc by adding the following lines:

xnoremap "+y y:call system("wl-copy", @")<cr>
nnoremap "+p :let @"=substitute(system("wl-paste --no-newline"), '<C-v><C-m>', '', 'g')<cr>p
nnoremap "*p :let @"=substitute(system("wl-paste --no-newline --primary"), '<C-v><C-m>', '', 'g')<cr>p

Then it's supposed to do copy/paste operations to/from + register between multiple instances. But in my case it doesn't. And when I use it in another terminal it pastes either lines from some previous session or nothing.
It's interesting thing, but after I had modified above lines this way:

xnoremap y y:call system("wl-copy", @")<cr>
nnoremap p :let @"=substitute(system("wl-paste --no-newline"), '<C-v><C-m>', '', 'g')<cr>p

made it just for curiosity and it started to work between instances using simple y/p.
So I can guess that I use register operations somehow not properly, then I tried it making "+y the "+p on some lines within one file and it worked correctly (but still not in separate files)
So I think such behavior is weird and makes me think I don't understand Vim clipboard mechanism in right way.
Please reply if you had same issue or correct me If I do something wrong.

Vim 8.2
Linux 5.10.16-arch1-1 x86_64
Terminal Alacritty.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

Christian Brabandt

unread,
Mar 2, 2021, 2:12:56 PM3/2/21
to vim/vim, Subscribed

xnoremap "+y y:call system("wl-copy", @")

I think Vim sees the " as a comment character. I wonder why you didn't get a no mapping found message.

Bogdan

unread,
Mar 2, 2021, 3:15:54 PM3/2/21
to vim/vim, Subscribed

I decided to stay with second variant:

xnoremap y y:call system("wl-copy", @")<cr>
nnoremap p :let @"=substitute(system("wl-paste --no-newline"), '<C-v><C-m>', '', 'g')<cr>p

Because:

  1. It just works.
  2. y/p are most frequently used in work so they should be most universal options. Though I'm losing 'powerful advantages' of using + register between terminals, but I'll carry that weight!

Bogdan

unread,
Mar 2, 2021, 3:16:35 PM3/2/21
to vim/vim, Subscribed

I decided to stay with second variant:

xnoremap y y:call system("wl-copy", @")<cr>
nnoremap p :let @"=substitute(system("wl-paste --no-newline"), '<C-v><C-m>', '', 'g')<cr>p

Because:

  1. It just works.
  2. y/p are most frequently used in work so they should be most universal options. Though I'm losing 'powerful advantages' of using + register between terminals, but I'll carry that weight!

Bogdan

unread,
Mar 2, 2021, 3:16:38 PM3/2/21
to vim/vim, Subscribed

Closed #7922.

Reply all
Reply to author
Forward
0 new messages