I think with a little rejiggering, you can move the "if" to the
front:
:let i=1120
:g/XXXX/if i < 4000 | s/\zsXXXX\ze/\=i/ | let i=i+1 | endif
You might have to adjust for fence-posting errors I may have
introduced. The :g will still visit each line, but if the
threshold is passed, no action is taken on those lines.
-tim
Here's another attempt (untested)
:let i = 1120 | %g/XXXX/s/XXXX/\=(i<4000?i:submatch(0)) | let i += 1
Alternately, you might put a try/endtry block around the argument of the
":g" statement to catch the generated error, see
:help :try
:help :catch
:help :finally
Best regards,
Tony.
--
"Star Wars is adolescent nonsense; Close Encounters is obscurantist
drivel; Star Trek can turn your brains to purée of bat guano; and the
greatest science fiction series of all time is Doctor Who! And I'll
take you all on, one-by-one or all in a bunch to back it up!"
-- Harlan Ellison
submatch() can only be used in a |sub-replace-expression| -- an
expression given after \= in the "replace by" string of a
":s[ubstitute]" command. Otherwise I would expect it to be available in
any Vim version compiled with expression evaluation. IOW, if you don't
have it, you probably have a crippled-down Vim ("Small" or "Tiny", see
near the top of the output of ":version"). In that case I would
recommend to install a better-equipped version of Vim (vim-enhanced
and/or vim-x11 in a RedHat-like Linux distribution; Steve Hall's
https://sourceforge.net/project/showfiles.php?group_id=43866&package_id=39721
on Windows; or compile it yourself as a Big or Huge build, see the two
HowTo pages on my Vim site http://users.skynet.be/antoine.mechelynck/
Best regards,
Tony.
--
Reporter (to Mahatma Gandhi): Mr Gandhi, what do you think of Western
Civilization?
Gandhi: I think it would be a good idea.