Is there anyway to fix the xclip relate with neovim "+y?clipboard: error: Error: target STRING not available

630 Views Asked by At

When use neovim to copy content to system clipboard with "+y way. It works well if neovim's window doesn't close, if I close neovim window, the content of + register will disappear. for example, then if I use tow neovim, one copy someword, another can paste easily, but is the copy none close window, then paste one's :reg will show in "+ line: clipboard: error: Error: target STRING not available This happens after I cp the whole /home to /mnt/home, and rm /home, then reboot I found the issue.

I try to reinstall xclip and neovim, didn't work. But install xsel(before I didn't install) and uninstall xclip could slove this issue. However, my tmux will use 'xclip -in -selection clipboard' So, I can't use my tmux to copy into system board. Reinstall the xclip, the neovim will choose the xclip automatically, then the clipboard broken again. I believe this can be solved, hoping someone can solve the problem, fix the xclip issue, or provide some suggestion about tmux set xsel.

1

There are 1 best solutions below

0
On

There is an open xclip issue related to Error : target STRING not available https://github.com/astrand/xclip/issues/38.

I recommend switching from xclip to xsel. Neovim now prefers xsel over xclip due to reports of issues. See pull request https://github.com/neovim/neovim/pull/9302.

Reinstall the xclip, the neovim will choose the xclip automatically, then the clipboard broken again.

You should check your Neovim version. The change to prefer xsel over xclip was introduced in Neovim v0.9.0.

If you can't upgrade to v0.9.0 then you can override the clipboard provider by setting the g:clipboard. See https://neovim.io/doc/user/provider.html#g%3Aclipboard for details on how to do that.

To configure a custom clipboard tool, set g:clipboard to a dictionary. For example this configuration integrates the tmux clipboard:

let g:clipboard = {
  \   'name': 'myClipboard',
  \   'copy': {
  \      '+': ['tmux', 'load-buffer', '-'],
  \      '*': ['tmux', 'load-buffer', '-'],
  \    },
  \   'paste': {
  \      '+': ['tmux', 'save-buffer', '-'],
  \      '*': ['tmux', 'save-buffer', '-'],
  \   },
  \   'cache_enabled': 1,
  \ }