Wednesday, January 07, 2009

Vim search and replace, with increment

:let i=1 | g/foo/s//\=i."morestuff"/ | let i=i+1

5 comments:

Nonsence said...

thanks mate :)

usefull cmd :)

Todd said...

Thanks for making vim even cooler!

baynaa said...

Works perfect!

Chris Hoffman said...

with backreferences?

unclechu said...

Perfect! But if needs submatch:

First string
Second string
Third string

let i=1 | g/\(str\)/s//\=i.' '.submatch(1)/ | let i=i+1

First 1 string
Second 2 string
Third 3 string

Pyjamas