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 foox
This is the first line
one,two,three,four
1,2,3,4
ichi,ni,san,shi
This is the last line
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.com> wrote:
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