Make vim yankings global via a shared text file

buffervimwindowyank

In a nutshell, I want the following:

  • y(ank) actually writes the yanked text to a line in a text file, maybe in your .vim directory
  • that line is prefixed with the name of the register, so "qyy yields q>my line of text
  • p(ut) gets the expected result from that file

The reasoning is to get more of a 'system wide' vim buffer to solve this problem:
Sharing Vim Yank Register

Best Answer

I had the same question. I found following simple solution:

Edit your .vimrc file. Add the lines

map <C-y> <Esc>:'<,'>! cat \| tee ~/tmp/.myvimbuf<CR>

map <C-p> o<Esc>:.!cat ~/tmp/.myvimbuf<CR>

map <C-P> O<Esc>:.!cat ~/tmp/.myvimbuf<CR>

and make sure the directory ~/tmp is in place.

Open two instances of vim. If you now highlight a portion of text in one instance and hit CTRL+y and then hit CTRL+p or CTRL+SHIFT+p in the other instance, you should get what you want.

Obviously, the key combinations could be modified to whatever you like.

This needs cat and tee; it should work on any Mac/Linux machine.

Related Question