[OT] Vim Question

This is for all the Rubyists out there who can really rock the Vim.
How do you invoke a shell command and pass arguments to said command?

function Put(computer)
  !rsync -v -rulptzCF string(getcwd()) . "/" string(a:computer) . ":"
. string(getcwd()) . "/"
endfunction

The idea here is that I want a Put function that takes a computer name
as an argument. This function will use rsync to copy all modified
files from the current working directory to the same directory on the
remote computer.

The reason for this is that I'm developing on Windows :frowning: but my code
needs to run on Linux and Solaris. Pushing code to the machines where
autotest will run it is the desired outcome. I don't want to have to
drop out of vim and into a shell prompt each time I do this.

The function I gave above is total crap, but hopefully it conveys the
idea I want to accomplish. Any help or thoughts? A simple example,
maybe?

TwP

here i type

   :r !echo arg1 arg2

which says

   read in the output of 'echo arg1 arg2'

yielding

   arg1 arg2

into my file. if you don't want output you can do things like

   :! cp % %.bak

which makes a backup of the current file

lastly, you can write nifty 'filters' that read stdin. my favourite is this
one

   harp:~ > cat ~/bin/columnize

   #!/usr/bin/env ruby
   n = Integer((ARGV.shift || 1))
   while((line = STDIN.gets))
     line.strip!
     fields = line.split(%r/\s+/)

     rows =
     while not fields.empty?
       rows << (row = )
       n.times do
         field = fields.shift
         row << field if field
       end
     end
     rows.each{|row| puts row.join(' ')}
   end

now, given a bunch of words like these

   foo bar foobar barfoo a b c

i can highlight them using 'shift-v movement keys (hjkl)', which hightlights
by line. then, while highlighted, i type ':!columnize' which turns the words
into this

   foo
   bar
   foobar
   barfoo
   a
   b
   c

if, instead, i type, ':!columnize 2', the output is

   foo bar
   foobar barfoo
   a b
   c

hope that gives you some ideas. btw. there is probably a way to do all that
in vim, writing little ruby scripts let's me use them from the shell too, as
in

   cat list | columnize 3

and it's easy to do anyhow.

cheers.

-a

···

On Mon, 21 Aug 2006, Tim Pease wrote:

This is for all the Rubyists out there who can really rock the Vim.
How do you invoke a shell command and pass arguments to said command?

function Put(computer)
!rsync -v -rulptzCF string(getcwd()) . "/" string(a:computer) . ":"
. string(getcwd()) . "/"
endfunction

The idea here is that I want a Put function that takes a computer name
as an argument. This function will use rsync to copy all modified
files from the current working directory to the same directory on the
remote computer.

The reason for this is that I'm developing on Windows :frowning: but my code
needs to run on Linux and Solaris. Pushing code to the machines where
autotest will run it is the desired outcome. I don't want to have to
drop out of vim and into a shell prompt each time I do this.

The function I gave above is total crap, but hopefully it conveys the
idea I want to accomplish. Any help or thoughts? A simple example,
maybe?

TwP

--
to foster inner awareness, introspection, and reasoning is more efficient than
meditation and prayer.
- h.h. the 14th dali lama

Tim,

This is for all the Rubyists out there who can really rock the Vim.

Well, one tries.

The idea here is that I want a Put function that takes a computer name
as an argument. This function will use rsync to copy all modified
files from the current working directory to the same directory on the
remote computer.

The reason for this is that I'm developing on Windows :frowning: but my code
needs to run on Linux and Solaris. Pushing code to the machines where
autotest will run it is the desired outcome. I don't want to have to
drop out of vim and into a shell prompt each time I do this.

Why not just edit the files on the machines where autotest runs?

Vim has a mechanism for editing remote files via ftp, rcp, scp, http and others. I've used it before and it saved a lot of fiddling around with scripts outside vim. Here's some more information: tips : vim online

Good luck,
Andy

You can also just type !! with no colon to do the same thing (two less characters!).

···

On Aug 20, 2006, at 5:50 PM, ara.t.howard@noaa.gov wrote:

here i type

  :r !echo arg1 arg2

which says

  read in the output of 'echo arg1 arg2'

--
Luke Kanies
http://madstop.com | http://reductivelabs.com | 615-594-8199

That's a cool little fact to know, but it won't work for me :frowning:

The version controlled copies live on my laptop, but the code needs to
run on a few other machines. Also, when I'm not connected to a
network, it would be hard to edit the files. Thanks for the tip though
:slight_smile:

TwP

···

On 8/21/06, Andy Stewart <ruth_andy@fastmail.fm> wrote:

Why not just edit the files on the machines where autotest runs?

Vim has a mechanism for editing remote files via ftp, rcp, scp, http
and others. I've used it before and it saved a lot of fiddling
around with scripts outside vim. Here's some more information:
tips : vim online

Good luck,
Andy

Okay, the solution I came up with is to build up the command inside
one of the paste registers (@) and then execute that register. Here
is a simple example that will move to the current working directory
and do a file listing.

function FuncGetls( )
  let @g="!cd " . getcwd() . "; ls"
  @g
endfunction
command Getls call FuncGetls( )

My full solution for doing the rsync is this ...

command -nargs=1 Put call <SID>Put("<args>")
function <SID>Put(puter)
  let s:dir=escape(getcwd(), "\"") . "/"
  let @r="!rsync -v -rulptzCF " . s:dir . " " . a:puter . ":" . s:dir
  @r
endfunction

Now I can send all the files I've modified to another computer by
typing the following command ...

:Put panic

where panic is the name of the machine.

TwP

···

On 8/20/06, ara.t.howard@noaa.gov <ara.t.howard@noaa.gov> wrote:

here i type

   :r !echo arg1 arg2

which says

   read in the output of 'echo arg1 arg2'

yielding

   arg1 arg2

into my file. if you don't want output you can do things like

Why not just edit the files on the machines where autotest runs?

Vim has a mechanism for editing remote files via ftp, rcp, scp, http
and others. I've used it before and it saved a lot of fiddling
around with scripts outside vim. Here's some more information:
tips : vim online

Good luck,
Andy

That's a cool little fact to know, but it won't work for me :frowning:

The version controlled copies live on my laptop, but the code needs to
run on a few other machines. Also, when I'm not connected to a
network, it would be hard to edit the files. Thanks for the tip though
:slight_smile:

Sounds like a job for DSCM such as darcs, git or mercurial. :wink:

···

On Aug 21, 2006, at 10:27 AM, Tim Pease wrote:

On 8/21/06, Andy Stewart <ruth_andy@fastmail.fm> wrote:

TwP