regex - Is it possible to mark the n-th occurrence of a pattern with n in vim? -


say have text following.

the man walking, , man eating.

how should use substitution convert following?

the man 1 walking, , man 2 eating.

i know can use :%s/\<man\>//gn count number of occurrences of word man , know /\%(\(pattern\).\{-}\)\{n - 1}\zs\1 can find n-th occurrence of pattern. how mark n-th occurrence?

any sincerely appreciated; in advance.

you'll need have non-pure function counts occurrences, , use result of function.

" untested let s:count = 0 function! count()     let s:count += 1     return s:count endfunction  :%s/man\zs/\=' '.count()/ 

Comments

Popular posts from this blog

How to use SUM() in MySQL for calculated values -

loops - Spock: How to use test data with @Stepwise -