While working through vimtutor, I tried a variant on
:%s/old/new/g
by leaving off the g flag
:%s/old/new
and expected the substitution to only occur once in the whole file. After all, this mirrors the behavior of :s/old/new, which operates on the current line and only substitutes once unless the g flag is present.
However, the g the :%s substitution command does seem to matter, as both variants operate many times on the whole file. Is this documented anywhere, and how do you make sense of this discrepancy?
Workaround
I'm aware that I can replace just one instance anywhere in the file with
:%s/old/new/gc
and decline the prompt after the first substitution. I'm seeking understanding on the non-interactive version without the c flag.
:h :s_flags– statox Apr 17 '18 at 07:53