Vim Tips Wiki
Tip 66 Printable Monobook Previous Next

created 2001 · complexity basic · author Douglas Potts · version 5.7

This one is a one of my favorites from Dr. Chip, and I haven't seen it come across Vim tips yet.

Can use either visual, or marking to denote the text.

" transfer/read and write one block of text between vim sessions
" Usage:
" 'from' session:
" ma
" move to end-of-block
" xw
" 'to' session:
" move to where I want block inserted
" xr
if has("unix")
  nmap xr :r $HOME/.vimxfer<CR>
  nmap xw :'a,.w! $HOME/.vimxfer<CR>
  vmap xr c<Esc>:r $HOME/.vimxfer<CR>
  vmap xw :w! $HOME/.vimxfer<CR>
  nmap xr :r c:/.vimxfer<CR>
  nmap xw :'a,.w! c:/.vimxfer<CR>
  vmap xr c<Esc>:r c:/.vimxfer<CR>
  vmap xw :w! c:/.vimxfer<CR>


See also VimTip71.

Here is much simple version. Tested on Unix only.

"Copy and paste between different Vim sessions
nmap _Y :!echo ""> ~/.vi_tmp<CR><CR>:w! ~/.vi_tmp<CR>
vmap _Y :w! ~/.vi_tmp<CR>
nmap _P :r ~/.vi_tmp<CR>

Select your text, press _Y to copy the selected text or it will copy the whole file, then in another (or even the same) Vim session press _P to paste

VimTip21 seems to solve all of these issues.