Saturday, January 21, 2012

Re: Prefix lines with a counter

On Jan 22, 5:49 am, Chris Lott <ch...@chrislott.org> wrote:
> Here is something I constantly find myself needing to do:
...

(Sorry list readers, I find myself repeating this here yet again.)

While not simple, the following idiom is very flexible:

:let i = 1
:g/something/s//\=i/|let i+=1

In your example your something would be ^, and you'd perhaps want to
add the "." in the same substitute:

:g/^/s//\=i.'. '/|let i+=1

Easy to see where to change the initial value, the lines to be
numbered, and the increment.

Regards, John

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: