From: ara.t.howard@... Date: 2006-08-21T07:50:17+09:00 Subject: Re: [OT] Vim Question 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 :( 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 -- to foster inner awareness, introspection, and reasoning is more efficient than meditation and prayer. - h.h. the 14th dali lama