Use regex in vim to to replace with incrementing variable but reinitialize this variable at a specific word

19 views Asked by At

I have for the moment the following ex command:

:let a = 1 | g/B/ s//\=printf('%02d', a)/ | let a += 1

This command replace each occurrence of B by an incremented number. But, each time the word reinitialize appear in the file, a variable should be set at 0, without modifying noting to the word reinitialize. The variable should only affect the occurrences of B.

I can add at the end | g/reinitialize/ let a = 0. But this occur the replacement of the only first occurrence of B and ignore all the following ones.

How to do this?

0

There are 0 answers