Nevermind, I solved my own problem. it was right there in the online help for sub-replace-expression. The syntax to access the nth match in a \= expression is submatch(n).
So in my example, the correct line to achieve what I want is:
:let i=1 | %g/\(foo\|bar\)1/ s//\=submatch(1) . i/g | let i+=1
All I had to do was keep reading instead of skimming the documentation 🙂














Unsurprisingly, the Democrat pussies messed it up yet again.