I'm working on nand2tetris, and I end up with a lot of files that end up looking like this:
Bit(in=in[0], load=load, out=out[0]);
Bit(in=in[1], load=load, out=out]1]);
...
Bit(in=in[15], load=load, out=out[15]);
So I've been yanking the first line, then using 15p, and then doing :s/0/i/g
15 times (where i
is the index I need). I've noticed that I can replace this with :s/\[\d\]/\[i\]/g
, but even here I manually set the value of i
each time I run the command. Is there a command I can run so that i
is automatically calculated to be \d+1
and I can just repeat the command for each line, without manually specifying the value?
I would do it like Peter Rincker (on-the-fly macros are awesome) but here is another solution, just for the sake of it:
yy " yank current line
15p " paste 15 times
:,']s/0/\=line('.')-1/g " substitute every 0 from cursor to last
pasted line with the current line number