2

I understood that

:%s/foo/bar

replaces the first occurrence of 'foo' with 'bar' in each line and repeats the process for all lines.

My requirement is to stop skimming through lines after the replace is done in the first line where the match is found.

Please help me with this

1

1 Answer 1

3

You can use:

:%s/foo/bar/c

This will ask you to confirm that you want to make the substitution for every match, so you could accept the first with y and then press q to quit.

Another way that would free you from the need to interact with the confirmation interface would be:

:/foo/s/foo/bar

Here the first /foo/ is used as a line address (see :help 10.3 and :help cmdline-ranges) on which to apply subsequent commands. In this case the subsequent command is the s/foo/bar, so it only happens on the first line on which a match is found.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.