# substitution of increasing numbers per row

Each row is:

``````Or(a=a[0], b=b[0], out=out[0]);
Or(a=a[0], b=b[0], out=out[0]);
Or(a=a[0], b=b[0], out=out[0]);
``````

and I need:

``````Or(a=a[0], b=b[0], out=out[0]);
Or(a=a[1], b=b[1], out=out[1]);
Or(a=a[2], b=b[2], out=out[2]);
``````

I tried this solution as:

``````:let t=[]  # then ctrl-v
``````

But this increments each subsequent number, not per row. I couldn't find/understand other solutions.

Thank you!

Do you mind some Awk?

``````:%!awk 'gsub(/[0-9]+/,i+0){i++}1'
``````

This means:

• `gsub(/[0-9]+/,i+0)` If there is any number in the line, substitute it by `i+0`.
• `{i++}` If a substitution occurred in this line, increment `i`.
• `1` is a short for "print the resulting line".

In case you are wondering, `i+0` forces the conversion of `i` to integer in the case `i` is unset (case which happens in the first line).

If you visual highlight with `ctrl-v` a column of zeros and press `g ctrl-a` it will consecutively increase them. If you want to leave the first one as a zero, you should omit that from the selection. Also, if there are many columns, like in your example, it's a good idea to start from the rightmost, since if the numbers increase enough to require more digits anything to the right of the original column will now be misaligned after the digit increase.

If you have a lot of columns `awk` will probably be better, but for a few, I this is probably easier to do (and remember, at least for me :)).

• Awesome! Just when you think you've learned all you need to know, the Vim help surprises you with a new gem: `:help v_g_CTRL-A`. Thanks, @fbence! Jul 20, 2022 at 17:43
• Just a note: `v_g_^a` is dotable (`.` works), as any command. Just put your cursor on the second column, no need to enter visual mode again (that wouldn't work). Jul 20, 2022 at 19:44
• @Biggybi nice one! thanks! Jul 20, 2022 at 21:12
• @PhilR exactly how I usually feel :D Jul 20, 2022 at 21:13