Jussi
I tried various ways but it seems the only way to insert a line from a script is to use the append() function (do help append) specifying the line number as a parameter.
I tried it on with an example script "moo.vim" as shown below
flapeccino@T4410 ~ $ cat moo.vim :1,$s/ /,/g :call append(0,"This is the first line") :call append(line('$'),"This is the last line") :w foox :q! flapeccino@T4410 ~ $ cat foo one two three four 1 2 3 4 ichi ni san shi flapeccino@T4410 ~ $ vi -s moo.vim foo flapeccino@T4410 ~ $ cat foox This is the first line one,two,three,four 1,2,3,4 ichi,ni,san,shi This is the last line flapeccino@T4410 ~
BTW thank you for this, I have been using vi for a very long time, and I never realized until now that at least in its vim incarnation it has such a powerful scripting language. I've used sed/awk/perl but never happily and always felt an inferiority complex to the emac brethrens showing off with their emac lisp macros. It must be a deficiency but my fingers never could do emacs.
On Fri, Jun 10, 2011 at 11:42 AM, Les Mikesell lesmikesell@gmail.comwrote:
On 6/10/2011 1:03 PM, Jussi Hirvi wrote:
On 10.6.2011 18.39, flapeccino@gmail.com wrote:
There is a good article on vimscript here:
http://www.ibm.com/developerworks/linux/library/l-vimscript-1/index.html)
Sorry there was a typo, the correct URL is:
http://www.ibm.com/developerworks/linux/library/l-vim-script-1/index.html
Thanks, I found that already, and it is a good one. But it didn't help me solve my problem about cursor motions.
Maybe my question is wrong - maybe I should just use line ranges in commands, for example for the first line: :1,1s/foo/bar/g and for the last line: :$,$s/foo/bar/g
I thought the point of using vim instead of something more appropriate for scripting was that you already knew how to use it. Why not do: vim -W script testfile and go through the motions you know (which can include 1G to go to the 1st line and G to go to the last). Then run vim -s script realfile to do the same actions again.
-- Les Mikesell lesmikesell@gmail.com _______________________________________________ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos