I am editing a file and i want to change only a specific word with another word, but only for first N occurrences. I tried multiple commands
N :s/word/newword/
Using a disposable recording allows you to control exactly how many changes you do:
qq " start recording in register q
/foo " search for next foo
cgnbar " change it to bar
q " end recording
11@q " play recording 11 times
See :help recording and :help gn.
Another way, using :normal:
:norm! /foocgnbar <-- should look like this: :norm! /foo^Mcgnbar^[
11@:
See :help :normal and :help @:.
Or simply:
:/foo/|s//bar
11@: