Search code examples
regexvimreplace

Regex for search and replace in vim


I have a file which has multiple entries like this:

Abcd:abcd:*sometext*:klm:xyz/abc
Abcd:abcd:R%fs90uw:klm:xyz/abc

Now, I want to replace "klm" with "qrs" for only those lines which have the "sometext" string in the line.

How can I do this using the search and replace feature in vim?

Thanks!


Solution

  • :g is your friend:

    :g/sometext/s/klm/qrs/g