Far too often, I've started a global search replace with confirmation, and discovered part way thru that I should have done a different search. Here's a silly example


Suppose my goal was to change all occurences of the word he with she and I unfortunately wrote


and wanted to interrupt the operation after the second change. Obviously I could enter n or CTRL C till I got to the end but when there are lots of candidates this gets pretty tedious. What I'd like to be able to do is simply cancel the search in midstream, but as far as I can tell this is not possible. Or is it?

  • 2
    ctrl-c interrupts the whole g/ expression
    – Mass
    Aug 30, 2021 at 23:01
  • for me, ctrl-c interrupts each individual replacement, but i have to hit ctrl c for as many times as there are instances of the search. Is that normal?
    – Leo Simon
    Sep 1, 2021 at 3:24

1 Answer 1


Run your command as :%substitute/{pat}/{repl}/gc which is equivalent (in this particular case), and use <esc> or q to stop substituting.

The difference is :global/{pat}/substitute//{repl}/gc runs a separate and independent susbtitute command for each line matching {pat}, while :%substitute… runs a single command over the whole file.

  • Perfect and thanks for the explanation
    – Leo Simon
    Oct 6, 2021 at 19:56

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.