Make vim yankings global via a shared text file

4

1

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

gggg

Posted 2011-04-04T19:05:09.500

Reputation: 41

Answers

1

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.

max

Posted 2011-04-04T19:05:09.500

Reputation: 11

1ah, very nice. This would also allow paste while in insert mode. – gggg – 2011-06-17T15:47:29.020

0

All you really need is to use the viminfo feature. Put something like the following in your ~/.vimrc file.

set viminfo='20,\"90,h,%

Then butters, marks, and more are persisted between session automatically. See :help viminfo for more information.

Keith

Posted 2011-04-04T19:05:09.500

Reputation: 7 263