vimrepeatinsertion

How to repeat last substitution of Insert Mode in VIM?


Consider I changed a word to "Next" (cwNextESC). After this I do, say, change till semi-colon (cf;). At this point, I want the previous substitution (Next) to be inserted here. Is this a way to do this? I think there is a way to do it!

The point is with any subsequent edits invoked by different means (like 6S, cf;, 3cw, etc), I want the insertion done in the first instance to be repeated.


Solution

  • That last insert can be repeated using Ctrl-A (see :help i_CTRL-A). Pressing cf;<C-A> will insert "Next" over everything including the next semi-colon. This solution was pointed out by user yolenover, all credits go to them.

    The last change is also stored in the . (dot) register (see :help quote.). If you want to avoid pressing the Ctrl key, you could also visual-select the text to the semi-colon and then put the contents of the dot register using vf;".p.