Regex for search and replace in vim

2019-07-29 10:38发布

问题:

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!

回答1:

:g is your friend:

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