Recently I learned the awesome command cgn
to repeat a change to a word. I’ve seen several answers advising its use, like this:
What is the best way to re-factor a variable name in vim?
and this:
How to find and replace in Vim without having to type the original word?
But the problem is that I can't add a repeat prefix to it. If I have, say, 10-20 occurrences, and I want to change them all, it's rather anoying to type 20 dots. If I add a prefix it jumps the lines and changes only one occurence, instead of repeating the whole change.
I can add a macro:
/foo<cr>qacgnbar<esc>.q20@a
But it's 5 keystrokes more. Well.. it's better than 10 or 20 keystrokes, but I thought there could be a better option.
How can I repeat cgn a number of times ?
:%s//\=@./g
if you've already searched (/
) for "foo" and changed (c
) it to "bar" earlier.