On 15/01/09 08:42, John Beckett wrote:
> Stephanus Schoonees wrote:
>> Could someone please assist me on how to put the amount of
>> lines in the vim buffer into a vim variable?
>
> :let numlines = line('$')
>
>> My aim is to repeat a macro/script "a" times in vim.
>
> If you are operating on the lines in the buffer, bear in mind stuff
> like:
>
>    for line in getline(1, line('$'))
>      " do something with line
>    endfor
>
> John

or (depending on circumstances)

1) marginally faster (I think) than the above; also compatible with Vim 
versions earlier than 7:

        let i = 1
        while i <= line('$')
                " do something; i is the line number
                let i += 1
        endwhile

2)
        :1,$call MyFunction()

        " if MyFunction is defined without the "range" option
        "       it will be called once on every line in the file.
        " if it has the "range" option it will be called just once.
        " In either case, within the function,
        "       a:firstline and a:lastline will be set
        "       to what their names imply.

3)
        :1,$g/^.*$/command

        " where "command" is any ex-command: it will be executed
        " once on every line which matches the pattern, so here
        " I chose a pattern which matches every line.

4) to execute some ex-command only on lines containing something other 
than whitespace

        :1,$v/^\s*$/command


Best regards,
Tony.
-- 
Bride, n.:
        A woman with a fine prospect of happiness behind her.
                -- Ambrose Bierce, "The Devil's Dictionary"

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

Reply via email to