4

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
:s/\d/\=len(add(t,1))/g

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

Thank you!

aerijman
  • 161
  • 4

2 Answers2

4

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 :)).

fbence
  • 677
  • 4
  • 12
3

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).

Quasímodo
  • 2,466
  • 9
  • 22