For example, let's say I want to put a number before every line that starts with the word "Do". The command would look something like :%s/^(Do )/1. \1/
, but what can I do so it will apply numbers consecutively instead of the same number each time?
Note that I'm well aware of the numerous ways to do this using macros and Ctrl-A, but for use in more complicated Ex-mode commands I would like to know the answer to exactly the title question.
For another example where a macro approach wouldn't be so easy, let's say I want to append a number to all instances of the word "Section", and have them consecutively numbered but restarting the count after each line that starts "Chapter". An Ex-mode command that can almost do this, save for actually incrementing the number to be added, is:
:g/^Chapter/;/^Chapter/-s/Section\zs/ 1/g
You can see that an easy method of incrementing numbers in the Ex-mode substitute command could be very useful.