I use Vim whole day, every day.

Combined with GNU Screen I have a really powerful development platform.

Unfortunately, I had a consistency problem with copy/paste text between different Vim instances (running in different iTerm2 tabs, or in separate GNU Screen windows).

When running CLI locally it is not a big deal as Vim has support for yank/paste to/from system clipboard (via * and + registers). It is not an issue if you work with MacVim either, as it has full integration with system clipboard.

My problem is that most of the time, when developing, I am connecting to different machines via ssh. There are number of solutions: for eg X11 Forwarding, using xclips.

But I wanted a more simple approach that

  • will require zero configuration on my part
  • will work 100% of time, disregarding from which machine I am connecting, whether I connect as ssh -x host etc

Most obvious solution is to use temp file, where selection is going to be yanked into, and (presumably from another vim instance running on the very same host) is going to be pasted from.

This trick, as many others, has been already discussed on Vim.Wikia.
All I needed to add to my Vim Bundle‘s .vimrc:

"copy the current visual selection to ~/.vbuf
vmap y :w! ~/.vbuf
"copy the current line to the buffer file if no visual selection
nmap y :.w! ~/.vbuf
"paste the contents of the buffer file
nmap p :r ~/.vbuf

Now, when working in different windows of GNU Screen (I have at least two instances of Vim – one with current code, and another with Unit Test suite), to move text between those intances, I just need to

  1. visually select code
  2. type ,y
  3. switch to another GNU Screen window
  4. type ,p

This four steps take less than a couple of seconds, mind you :)

,

Couple of days ago, Vim team released new version of their great text editor. Once I had a little time, that’s today, I upgraded all my boxes. There couple of new features that are particularly interesting:

Read the rest of this entry

,