Wednesday, January 07, 2009

Vim search and replace, with increment

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

6 comments:

Nonsence said...

thanks mate :)

usefull cmd :)

Unknown 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

Jerome said...

Wow it's 2019 and it is still very useful. Thanks!

Pyjamas