tommcdo / vim-exchange

Easy text exchange operator for Vim
MIT License
756 stars 23 forks source link

Clipboard error happens when used in NeoVim in WIN10 #55

Open zczsyqxl opened 3 years ago

zczsyqxl commented 3 years ago

I used this plugin in NeoVim, when I did the exchange via cxiw, I got the error information shown below:

clipboard: error invoking win32yank.exe: thread 'main' panicked at 'called Result::unwrap() on an Err value: WinAPI Error(1418)', src\libcore\result.rs:859 note: Run with RUST_BACKTRACE=1 for a backtrace.

I tried to add one line in the source code, or comment one call s:restore_reg(), then, the error is gone.

    51 call s:restore_reg('*', reg_star)
    52 sleep 100m
    53 call s:restore_reg('+', reg_plus)

In another hand, I try the same action in VIM, there is no error happened.

brooth commented 2 years ago

The exchange triggers double Cmd+C keypress on macOS which in my case opens up the Reverso app. Really enjoying

tuurep commented 1 year ago

I also have a noisy cmdline in Linux (Arch 6.4.12-arch1-1) and NeoVim

While it appears that the plugin works perfectly, almost every use of cx gives one of these two error messages:

clipboard: error: Error: target STRING not available
clipboard: error invoking xclip: Waiting for selection requests, Control-C to quit  Waiting for selection request number 1

I suspect this NeoVim issue is very relevant: https://github.com/neovim/neovim/issues/7054

Especially comment by jamessan (2017):

The clipboard provider was recently changed to display the provider's stderr via :echomsg so that there's a way for users to get error information. Apparently xclip, even with -quiet specified (unless you overwrote the command), dumps non-error data to stderr.

However I can't really gather what I should do to fix the issue. I don't understand how the system clipboards are even relevant in this plugin, so I tried to just swap * with a and + with b in the script and everything looks like it works like it should.

Here is the commit: https://github.com/tuurep/vim-exchange/commit/e5af0b9bcd83d7b85a4cd6c2c860beb0b00915d1

Edit: Ah yes, the script doesn't explicitly set anything to reg a or reg b so I might as well remove the save_reg and restore_reg lines for * and +.

Therefore this is not a fix.