Tuesday, December 15, 2009

Re: Vim client-server communication

On Dec 15, 2:44 am, Chris Jones <cjns1...@gmail.com> wrote:
> On Tue, Dec 15, 2009 at 01:35:53AM EST, Marc Weber wrote:
> > > In any event, thanks much for your comments. I'll study your script when
> > > time allows, and I'm sure things will become a lot clearer.
>
> > Hi Chris,
>
> > I'm unsure what you want to do.
>
> :-)
>
> No wonder, I haven't a clue myself.
>
> It's just something I ran into and was wondering if other users had put
> it to good use.
>
> > you can just do
>
> > feed_to_vim(){
> >   "$@" > /tmp/file
> >   vim --server --command :cfile /tmp/file
> > }
>
> Oh, right.. that definitely works.
>
> I also tried to pipe the output of a command, which works fine when
> running a local instance of Vim, i.e. -
>
> $ ls | vim -
>
> .. but when I try something like:
>
> $ ls | vim --remote -
>
> .. all I see is that the default vim server opens an empty buffer on a
> file named '-'.
>
> The help file warns about this briefly:
>
> "This doesn't work, all arguments after --remote will be used as file
> names [..]"
>
> > Syntax is wrong. But you get what I want to show you.
>
> That's exactly what I did, initially.
>
> Another fun situation is that you are exploring the file system on
> another terminal and issue a:
>
> $ less interesting_file
>
> Provided the $EDITOR environment variable is set to something like 'vim
> --servername VIM --remote-tab' for instance, and you feel like bringing
> up the file in an editor for some reason, you can hit the 'v' less
> command and this will create a buffer in 'VIM' loaded with the contents
> of 'interesting_file'.
>
> That's what I meant by 'amazing your friends' since though it has its
> merits, I don't see this particular example as being very useful,
> probably not enough to justify the overhead and added complexity.
>
> > If you really want to have a look at my code ..
> > Let me warn you: Pieces are bloated and buggy.
> > I still use them everyday. They are quite useful to me.
>
> Well, since it's the only utilization of the feature I'm aware of at
> this time, I guess I'd better take a look.
>
> > Maybe rephrase what you want to do rather than trying to guess what
> > I'm doing :)
>
> I want to better understand the feature and find out if it might provide
> useful editing strategies that might make life at the terminal more of a
> adventure.
>
> I try never to get stuck with the way I do things at a given point in
> time, because that's when method turns to filthy habits. An example of
> this is that I started using tabs not so long ago and thought, now
> that's something really useful. Retrospectively, I realize that almost
> everything you can do with tabs, you can do a lot better with windows
> and a couple of commands such as :ls/:ls! and :hide, or possibly the
> BufferExplorer plugin and save yourself the aggravation of periodically
> going through all your open tabs and closing those that are no longer
> useful. I'm not surprised that this GUI-like feature leads to 'desktop'
> clutter and inefficient editing. So I'm looking into switching to a a
> mult-buffer strategy that only uses tabs for what they are good at -
> there was a nice post about this on the list not long ago, and move to
> the more natural strategy of working with just one viewport and moving
> back & forth between buffers.
>
> Well, to get back to the client-server feature, I just wanted to make
> sure that I was not missing out on something that might change the face
> of my editing, so-to-speak, once I found out what the mavens were
> secretly doing with it..
>
> In other words, this feature caught my eye and I began to suspect tht it
> is not there to add a few hundred lines of code, and nothing else..
>
> So far I haven't seen anything in Vim that wasn't there for a reason.
>
> > Have fun!
>
> That, I will.. :-)
>
> CJ

Not sure how relevant this is to your situation, but I use the client-
server for a few things in my day-to-day
work environment:

1. all MAN pages all show up under one gvim [I'm not an expert BASH
writer]:
function man() {
gvim_server="MANPAGES1"
title=+"set titlestring="Man_Page"
silent="--remote-silent"
oldIFS=$IFS
IFS=

# Keep track of previously run 'man pages'
# this speeds up the process of looking at the same MAN pages over
and over again...
if [ ! -e /tmp/man.$* ]; then
/bin/man $* | col -b cat >/tmp/man.$*
fi
gvim --servername $gvim_server -R $title $silent /tmp/man.$* >/dev/
null &
IFS=$oldIFS
}
2. In a perl script I open a desired file in a remote gvim and goto
the specified line number:
# This is a stripped-down version of my code
my $file = "path/to/file-name.ext";
my $viewer = "/bin/gvim";
my $editor_options = '--servername PDU_VIM -R --remote-silent +
\"set filetype=MIB|LINE_NUM\"';
$editor_options =~ s/LINE_NUM/$requested_line_number/;
system "$viewer $editor_options $file";

It appears to work reasonable for my needs :-)
--
Mike

--
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php

No comments: