Wednesday, January 07, 2009

Vim search and replace, with increment

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

6 comments:

  1. thanks mate :)

    usefull cmd :)

    ReplyDelete
  2. Thanks for making vim even cooler!

    ReplyDelete
  3. 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

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

    ReplyDelete