rkitover / vimpager

Use Vim as PAGER
http://www.vim.org/scripts/script.php?script_id=1723
Other
769 stars 72 forks source link

system clipboard is clobbered #255

Closed damnskippy closed 3 years ago

damnskippy commented 3 years ago

Using vim 8.2 patch 769 on linux, I notice that whenever I pipe something through vimpager the system clipboard gets wiped out. Best I could isolate this down to is that this is related to my clipboard setting in vimrc. When I set clipboard to unnamedplus (which is my preferred setting) in vimrc then the system clipboard is clobbered after invoking vimpager. If I don't set the vim clipboard setting, then contents of the system clipboard are preserved. Is this expected? I work around this now by doing the following, but just would like to understand this better and not do this if not necessary.

    if !exists('g:vimpager.enabled')
        set clipboard=unnamedplus
    endif

I can also try building latest vim sources if that's the issue. Thanks.

rkitover commented 3 years ago

I've reproduced your issue on vim 8.1 in ubuntu with the vim-gtk3 package.

damnskippy commented 3 years ago

Thanks - but unfortunately I still see the issue with this change for whatever reason :( Removing my clipboard setting in vimrc avoids the issue as before.

rkitover commented 3 years ago

I cannot reproduce this anymore after this change, both the selection buffer and the clipboard are intact after vimpager exits.

I am using vim 8.2 patch level 814 on gentoo with X support.

Can you see if you can reproduce this issue with this minimal vimrc:

set mouse=a
set ttymouse=xterm2
set clipboard=unnamedplus
filetype plugin indent on
syntax enable

Thanks!

damnskippy commented 3 years ago

Still a mystery. I had tried yesterday with only the clipboard setting as the only line in my vimrc yesterday and could repro the issue. I just tried now with the minimal vimrc above and see the issue. I also pulled the latest vim sources and compiled, so now I'm up to 8.2 patch 1544. On ubuntu xenial (16.04), FWIW. Removing the clipboard setting from my vimrc avoids the issue in all these cases. Another clue I found is that if I unset my $DISPLAY env variable the issue is avoided as well. Even without the change in 145cf10 if I unset the DISPLAY env var, or the clipboard setting in vimrc, they both avoid the issue. Not sure if something in my environment or what. If there's any debug info I can collect, I'd be happy to. Or I could just use one of these workarounds and get by. I was only curious about what is going on and trying to understand.

damnskippy commented 3 years ago

Some quirk about something somewhere in X might be causing this is my guess. For now I removed the conditional in vimrc I was using for work around, and instead aliased less to a simple wrapper shell script in which I unset DISPLAY first and then call vimpager from there. This preserves the clipboard for me.

rkitover commented 3 years ago

To be clear, you are talking about the X clipboard and not the selection buffer?

I forgot to mention, when you are testing the minimal vimrc example, also move your ~/.vim out of the way so that no scripts get autoloaded.

When you load vimpager, what are the values of:

:4verbose set clipboard?
:reg +
:reg *
damnskippy commented 3 years ago

Some additional observation: I see that the issue of clipboard getting wiped occurs only in passthrough mode. If the piped contents don't fit the screen and vim is opened, then everything works as expected, clipboard contents are not lost.

The clipboard I'm referring to has its contents created via xsel -i --clipboard. This is actually done via the tmux copy-command setting, FWIW.

With the minimal vimrc,

:4verbose set clipboard?
  clipboard=unnamedplus
        Last set from ~/.vimrc line 3

No surprises here I guess. Also in the non-passthrough mode, when vim is opened both registers + & * show the clipboard contents correctly and they are preserved in the end. It comes down to vimcat/passthrough mode it seems - not sure if that provides any clues. I moved my ~/.vim folder as well. Thanks for all the responses.

rkitover commented 3 years ago

Thank you, this is very helpful, I will do some further debugging.

rkitover commented 3 years ago

I tracked this down to vimcat, and I used your idea of unsetting DISPLAY to fix it.

Please give it a try.

damnskippy commented 3 years ago

Thanks - this works for me.