Question

I've been trying to find out how to copy and paste between instances of vim/gvim and haven't been able to find an answer. I have two different gvim windows open in Linux and I'm trying to copy and paste between those two. I know you can do this within tabs of one gvim window, but I have found nothing on two separate ones.

I've attempted to yank it from one window and paste it into the other, copy it using ctrl+shift+c and similarly ctrl+shift+v, and using the mouse to copy and paste, but to no avail. Is there a way to do this?

Was it helpful?

Solution

I'd use system-wide buffer. Which is "+" in vim: "+yy, then in other instance "+p.

Edit: Explanation (kinda).

Double quotes followed by anything means "use named buffer instead of default one for the next copy or paste operation". "+ means use "+" which is the system clipboard (and thanks to other answers here I now know about * which is handy too).

yy means "copy current line" - quite a lot of vim operations can be "doubled" like that to work on current line. dd deletes a line, >> indents a line etc.

OTHER TIPS

As the previous answer suggests, you can use the register linked to the clipboard, which by default is "*" or "+".

On the other hand, why do you need to run multiple instances of gvim? You can always 'send' the name of the file you want to edit to the currently running instance of gvim. In any terminal simply type vim --remote-silent fiename and voila, you can use one instance of gvim and all of its registers.

You can add the following to your vimrc file (or create one, if you haven't done so yet: vim ~/.vimrc)

if has("gui_running")
  vmap <C-S-x> "+x
  vmap <C-S-c> "+y
  imap <C-S-v> <Esc>"+gP
endif

Now when gvim is running, control+shift+v will paste while you're in insert mode, and control-shift-x and control-shift-c will cut/copy while in visual mode (like when you've selected some text)

Use one of the X11 clipboard : "* (PRIMARY) or "+ (CLIPBOARD).

Here is an example with the primary clipboard :

To yank : "*y{motion}

To paste : "*p

For further explanation : :h quotestar and :h quoteplus

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top