# Substitution alternating a pattern

I have a transcription file that looks like this:

[09:46] question

[10:25] question

[10:27] question


and so on...

Now I would like to add an identifier right after the time like this:

[09:46] I1: question

[10:25] I2: question

[10:27] I3: question


and so on...

I know I can number each line like this:

:let i = 1 | g/]/s//\=printf("] %02d ", i)/ | let i = i+1


but how could I alternate the I and A?

Something like the following should work:

let ind=['I', 'A']
let i = 1
let j = 1
g/]/s##\=printf("] %s%02d ", ind[i%len(ind)], j)#|let i+=1|let j=(i%2==1?j+1:j)


as mentioned by @JürgenKrämer you can get rid of the second variable j and use this:

let ind=['I', 'A']
let i = 0
g/]/s##\=printf("] %s%02d ", ind[i%len(ind)], i / len(ind) + 1)#|let i+=1

• thanks, it works like a charm! just one small thing: in order for the sequence to start with the 'I' the ind has to be like this: ind=['A', 'I'] Jul 6, 2021 at 8:54
• You can get rid of variable j if you start to count from zero and replace j with i / len(ind) + 1 inside the call to printf(): let ind=['I', 'A'] let i = 0 g/]/s##\=printf("] %s%02d ", ind[i%len(ind)], i / len(ind) + 1)#|let i+=1 Jul 6, 2021 at 13:36
• thanks @JürgenKrämer cool improvement, let me amend the answer Jul 6, 2021 at 14:21