In Vim the closest you can get is (as Ingo's answer and Christian's comment mentioned) is:
augroup viminfo
autocmd!
autocmd FocusLost * wviminfo
autocmd FocusGained * rviminfo
augroup end
It's important to realize that the Focus*
autocommands aren't always run when you use Vim from a terminal, especially not if you're using tmux or screen. You should test this first by using :au FocusLost :echoerr "Focus lost!"
.
As far as I know there is no good work-around if these autocommands don't work for you. Using other events (such as CursorHold
) seem problematic to me due to timing issues that will almost certainly crop up.
Neovim comes with "ShaDa", which is a replacement for Vim's viminfo system. One aspect where it's better is merging files from different instances, and while it doesn't directly support syncing between multiple instances (yet), this seems to work well for at least one Neovim developer:
augroup shada
autocmd!
autocmd CursorHold * rshada | wshada
augroup end
See :help shada-merging
for details on the merging process.