History
Article Edit this page Discussion

Copy and paste between sessions using a temporary file

From Vim Tips Wiki

Jump to: navigation, search

Tip 1268 Previous Next Created: June 21, 2006 Complexity: basic Author: brudermarkus Version: 5.7


Sometimes I need to copy and paste stuff between Vim sessions. There are some proposals on how to do this with the clipboard, but here is an alternative (should work for any OS):

  • Hit Ctrl+C to copy the current line or current visual selection (it will be saved to the file ~/.vbuf).
  • Hit Ctrl+V to paste the contents of the previous copy action.

These mappings work in "normal" and "visual" mode.

"custom copy'n'paste
"copy the current visual selection to ~/.vbuf
vmap <C-c> :w! ~/.vbuf<CR>
"copy the current line to the buffer file if no visual selection
nmap <C-c> :.w! ~/.vbuf<CR>
"paste the contents of the buffer file
nmap <C-v> :r ~/.vbuf<CR>

[edit] Comments

Registers are stored in the viminfo file. Isn't this a more functional approach? See :help viminfo, :help 21.3.


Extremely useful - I use a variation of this every day: VimTip66


This is fine when you're on a system that maps copy and paste to ctrl-c or ctrl-v.

By default Vim doesn't do that. There's overrides to allow it to do so on Mac and Windows which makes Vim think I want to quit or then messes up the ability to do column selections on Linux.

I prefer sticking with the "+Y and "*Y methods to yank into standard registers. Those work consistently on Vim on Linux, Mac and Windows.


Rate this article:

Share this article:

Hubs Highlights International Sites Wikia messages
Entertainment
Gaming
Cartoons & Comics
Science Fiction
Hobbies
Sports
See all...
Grand Theft Auto Wiki
Doctor Who
Legend of Zelda Wiki
Terminator Wiki
Everquest II Wiki
Mystery Science Theater 3000
German
Spanish
Chinese
Japanese
More...
Wikia is hiring for several open positions
Send this article to a friend
"Copy and paste between sessions using a temporary file"
 
 
Hi!

I thought you'd like this page from Wikia!

http://vim.wikia.com

Come check it out!
Send confirmation