Tip: #66 - Transfer text between two Vim instances
Created: April 20, 2001 13:46 Complexity: basic Author: Douglas Potts <dp--AT--orion.spectral-sys.com> Version: 5.7 Karma: 106/34 Imported from: Tip#66
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>
else
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>
endif
Comments
See also Tip #71.
Alexey Marinichev , June 4, 2001 11:17
It would be good if this could include a command to remove the .vimxfer file from the buffer list, otherwise it polutes the list and alternative file. This perhaps negates the benefit since you could just the * buffer as well with only a few extra keystrokes:
(highlight text)
"*y
Then to paste in another file or application:
"*p
peoter_veliki--AT--hotmail.com
, June 4, 2001 21:56
here is much simple version of it.. however tested on *nix only
"copy and paste betweeen 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 CTRL+_Y to copy, then in another (or even the same) vim session press CTRL+_P to paste
supergrass--AT--gmx.net
, February 9, 2002 5:43
Hello,
It is specified about how to copy text from one file to another, but what if we want to move a selected piece of text from code or particular text typed at the prompt i.e after :<Some Text>, then how will the process is done. I mean if we want to send the so called <Some Text> into a file for storage then how to we do it?
goutham4u--AT--hotmail.com , July 21, 2004 6:38
This tip is extremely helpful in Unix shells like bash where you can use fix command 'fc'
bheckel--AT--yahoo.com , July 25, 2004 6:58
VimTip21 seems to solve all of these issues
stephenm , January 7, 2006 14:04