You are not logged in.

#1 2008-02-17 05:49:51

peets
Member
From: Montreal
Registered: 2007-01-11
Posts: 936
Website

Communication between separate instances of vim

I have a window manager which does its job quite well. I don't like to use vim's windows/buffers/tabs --that's already managed by dedicated programs.

I'd like to be able to "yy" a line in one vim window and "p" it in another. Right now I do this through the X selection buffer, but it's annoying to have to use it. Is there some way to have my different instances of vim communicate?

Offline

#2 2008-02-17 12:23:52

jordi
Member
Registered: 2006-12-16
Posts: 103
Website

Re: Communication between separate instances of vim

You could use "+y and "+p to  copy / paste to/from the clipboard

But I would prefer to use tabs/buffers within one instance of vi

Offline

#3 2008-02-18 00:16:06

awagner
Member
From: Mainz, Germany
Registered: 2007-08-24
Posts: 191

Re: Communication between separate instances of vim

something like this, maybe?

" copy text from one file to a different one
    nmap    _C      :!echo ""> ~/.vi_tmp<CR><CR>:w! ~/.vi_tmp<CR>
    vmap    _C      :w! ~/.vi_tmp<CR>
    nmap    _P      :r ~/.vi_tmp<CR>

Offline

#4 2008-02-18 05:59:58

peets
Member
From: Montreal
Registered: 2007-01-11
Posts: 936
Website

Re: Communication between separate instances of vim

jordi, that doesn't work for me. Maybe I'm not getting the keypresses right. I've tried '"', then '+', then 'y' and '"' and 'y' at the same time, in both normal and visual modes. I can't get it to copy to the X buffer.

awagner, that's interesting but I was hoping for a solution that would allow me to use vim's excellent keybindings. I didn't know about ":r"; that's pretty cool.

So this may be my first disappointment with vim.

There is hope nonetheless. ":help remote" brings up the very interesting "remote.txt" part of the vim documentation. It explains how one instance of vim can run as a server and others as clients, potentially over a network. I'm not sure what the implications of this are, but the document does mention "passing strings between clients" and something about the X selection buffer.

Alas, when I went to try it, vim told me it didn't know what I was talking about. I guessed that the option wasn't compiled in. The PKGBUILD in my abs tree does have "--with-features=big", which, if I understand the vim documentation properly, should enable the clientserver functionality. I don't know where the problem lies.

Offline

#5 2008-02-18 08:39:13

chicha
Member
From: France
Registered: 2007-04-20
Posts: 271

Re: Communication between separate instances of vim

Did you try to put this in your .vimrc  ?

set clipboard=unnamed

I use this setting on MS Windows to copy/paste from vim to window's clipboard, it may work on Linux too ...

Offline

#6 2008-02-18 10:51:00

awagner
Member
From: Mainz, Germany
Registered: 2007-08-24
Posts: 191

Re: Communication between separate instances of vim

peets wrote:

that's interesting but I was hoping for a solution that would allow me to use vim's excellent keybindings

You mean the "motion" keys? You should be able to bind the macros to any key you want, but if you want to use motion (^$Gwe etc) keys this would probably need some modification to the macros. But should be doable. Also, probably it's possible to re-map 'y' and 'yy' keybindings. Or do you mean something else?

Alas, when I went to try it, vim told me it didn't know what I was talking about. I guessed that the option wasn't compiled in. The PKGBUILD in my abs tree does have "--with-features=big", which, if I understand the vim documentation properly, should enable the clientserver functionality. I don't know where the problem lies.

Did you use vim or gvim? AFAIU clientserver communication uses some X11 mechanism to register/locate the communications partners and as long as you don't specify a --servername, vim (i.e. non-GUI) doesn't register as a server.

Maybe these are of some use, too:
http://www.vim.org/scripts/script.php?script_id=1234
http://vim.wikia.com/wiki/Copy%2C_cut_and_paste

Last edited by awagner (2008-02-18 11:04:24)

Offline

#7 2008-02-18 15:06:57

peets
Member
From: Montreal
Registered: 2007-01-11
Posts: 936
Website

Re: Communication between separate instances of vim

oops, I was using the minimal vim which comes with the standard installation. pacman -S vim enables the features mentioned above ("+y and client-server).

The server thing is useless for me: connecting to the "server" instance of vim to edit a different file creates a split window in the server-vim; that's what I'm trying to avoid.

awagner, I realize I know very little about vim. I'll read up on the topics you mentioned.

Offline

#8 2008-02-18 15:35:13

gorn
Member
Registered: 2008-02-01
Posts: 56

Re: Communication between separate instances of vim

As chicha mentioned

set clipboard=unnamed

will almost do what you want. If you yank something, then quit vim, then start a new vim, you can paste it. It's not the same as real-time copy/paste. But it's very helpful.

Offline

#9 2008-02-18 16:33:30

peets
Member
From: Montreal
Registered: 2007-01-11
Posts: 936
Website

Re: Communication between separate instances of vim

chicha, gorn: thank you! That does exactly what I want!

Vim is amazing.

Offline

#10 2008-02-18 16:43:18

chicha
Member
From: France
Registered: 2007-04-20
Posts: 271

Re: Communication between separate instances of vim

Vim is amazing.

I am glade it helped.

In your adventure with vim you will find out that 90% of your problems have a very simple solution such as this one.
For the other 9% you will find a vim script which does the job at vim.org.
For the 1% problems unsolved, you will write a short function or script which does the job yourself ... and you will enjoy having an editor which does 100% of what you want every where (console/Gui), at anytime (so light that it works even with 100% cpu load), on any platform (including Windows) and with any OS version (including old Unixes you will find in some places)

Enjoy !

Cheers,
Chicha

Offline

#11 2008-02-18 17:05:08

peets
Member
From: Montreal
Registered: 2007-01-11
Posts: 936
Website

Re: Communication between separate instances of vim

... and very rarely do I have "problems" with vim : o )

Offline

Board footer

Powered by FluxBB