Problem with the NeoVim clipboard

Problem

I can’t yank/paste from my Systems Clipboard to Neovim (or vice versa).
If I do :checkhealth in NeoVim I get following output

So the clipboard gets detected but if I do "*yy or "+yy the content in my Systems clipboard
does not paste
the content.

I tried it with xclip too (even though I am on Wayland) and the Clipboard gets the detected (again) but I have the same problem as mentioned above.

So what should I do in order to make it work?

Configuration

# /etc/nixos/configuration.nix
environment.systemPackages = with pkgs; [
  # ...
  neovim
  wl-clipboard
  xclip
];

Does using xclip as a custom clipboard work (see :h clipboard)?

vim.g.clipboard = {
  name = 'xclip',
  copy = {
    ['+'] = { 'xclip', '-quiet', '-i', '-selection', 'clipboard' },
    ['*'] = { 'xclip', '-quiet', '-i', '-selection', 'primary' },
  },
  paste = {
    ['+'] = { 'xclip', '-o', '-selection', 'clipboard' },
    ['*'] = { 'xclip', '-o', '-selection', 'primary' },
  },
  cache_enabled = 1, -- cache MUST be enabled, or else it hangs on dd/y/x and all other copy operations
}

I’m using this with vim.opt.clipboard = 'unnamedplus' to sync clipboards and it’s working without issue.

By the way, you can just run :checkhealth clipboard so you don’t check everything else, which might take some time depending on which plugins you have installed.

set clipboard=unnamedplus
along with wl-clipboard in a package list, that’s all you need for clipboard to work in (n)vim. xclip isn’t necessary.

I think the main issue is that the clipboard registers aren’t working as both tools seem to be detected correctly according to the original post.

I’m also suspecting this could be caused by plugins, which we can check by running nvim with no config:

nvim --clean

PS: I just want to note that I’ve had issues with wl-clipboard lately in which copying/pasting became very laggy at random times, which is why I’ve opted to using to xclip instead.

If you have both installed in your system, this is how they’re picked by default, according to :h clipboard:

Nvim looks for these clipboard tools, in order of priority:

  • |g:clipboard| (unless unset or false)
  • pbcopy, pbpaste (macOS)
  • wl-copy, wl-paste (if $WAYLAND_DISPLAY is set)
  • waycopy, waypaste (if $WAYLAND_DISPLAY is set)
  • xsel (if $DISPLAY is set)
  • xclip (if $DISPLAY is set)

Thank you kind stranger!

1 Like