Vim/gvim failing to put X11 clipboard in registers “+ or ”*

clipboardvimvncx11

Due to the lack of security with standard vino server, I switched to use x11vnc on my linux (with Xubuntu 14.04) box and SSVNC on the windows side.

With vino, cut and paste from windows to Linux and windows, in the two directions, was flaky(1) but when it worked, it worked for every program; I could use the vim register "+ without problem. I run(2)

autocutsel -fork 

normally so that the "middle click" and ctrl-c/v selections are the same.

Now that I use x11vnc (called with: x11vnc -forever -repeat -safer -usepw -ssl -autoport 6000) to have a safe, encrypted connection, a problem arose:

  1. I can copy on windows and paste in the remote linux terminals, libreoffice etc. without any problem, in both directions.

  2. In vim, or gvim, any attempt to paste with "+p or "*p says E353: Nothing in register *

  3. Again in vim or gvim, the other way around does work: if I "+yy then I can paste the thing on the Windows side.

As anyone any clue about this problem? The strange thing is that paste works everywhere I checked but in vim

Package                 Installed       Previous        Now             State
=======================-===============-===============-===============-=====
vim                     2:7.4.052-1ubuntu3  2:7.4.052-1ubuntu3  2:7.4.052-1ubuntu3  install
vim-gnome               2:7.4.052-1ubuntu3  2:7.4.052-1ubuntu3  2:7.4.052-1ubuntu3  install

Footnotes:

(1) can't find the bug now — it is reported. It stops working after a while.

(2) I tried with and without. No changes.

Best Answer

Since I do not know which x11vnc you are using (I have three different versions, there are others) this is a tutorial to troubleshoot this specific problem.

First is to understand the clipboards involved. There are in most cases four of them involved. (More is possible if you use clipboard management tools.) X11 defines three clipboards: Primary, Secondary, and Clipboard. Secondary is seldom used, (and is almost certainly not your problem) so we will ignore it. Applications that use middle click to paste (xterm, et al) normally use the primary clipboard. Applications that do a windows style paste (click edit, click paste or control V) sometimes use just the clipboard clipboard. Some applications do both (Google Chrome pastes from primary with a middle click and from clipboard with a control V). Next is the VNC clipboard (just one) and there is the windows clipboard. (If you are using a vnc viewer running on X11, things get more complicated, but that will make sense after thinking about this.) the VNC clipboard is special in that it keeps track of various updates of the other clipboards to keep them up to date. If you ignore the primary clipboard, this is fairly simple in that the most recently updated clipboard is copied to all the others. The challenge is that the desired behaviour of the primary clipboard is not well defined. I have seen the following behaviours of various vnc implementations:

  1. Ignore the primary, use the clipboard only.
  2. Ignore the clipboard, use the primary only.
  3. Use the most recent for unix to windows copies, copy to both for windows to unix copies.
  4. Try to be smart: use the primary only until the clipboard is used then only use the clipboard.
  5. Try to be smarter: use the primary until the clipboard is changed then ignore the primary until there is a change from windows, then use the next changed, again ignoring the primary after clipboard use.
  6. Try to be even smarter. (I never figured out what they were trying to do with this one, but usually it did the right thing)

Next is the tools. There are two tools I consider essential for debugging clipboard issues: a text editor (notepad works fine for this) and xclip. A windows clipboard viewer is nice but not essential.

Now the procedure: From each application in the group you are troubleshooting, select and copy some text checking the status of all three accessible clipboards. (The vnc clipboard is very difficult to view directly and not directly useful as it normally does not store the data, only the metadata.) answer these questions: which clipboard does each application use? what order are they used?

Hopefully this is enough information to get you started.