Match keyword on string and substitute under vi

Hi guys,

with sed when I need to make a substitution inside a line containing a specific keyword, I usually use:

sed '/keyword/ s/cat/dog/g'

This will substitute "cat" with "dog" on those lines containing "keyword". Now I want to use this inside vi, for several reason that I cannot explain, but I don't seem to find the right syntax.

Has any of you shell wizards the proper syntax to use? Thanks!

The corresponding command in vi is:

:g/keyword/s/cat/dog/g

Regards

Thanks a lot, it worked like a charm! :slight_smile: