Re: Is there a text-editor trick to write several identical lines of code while incrementing the numbers on each line ?
Posted by
Gerrit0 on
May 10, 2020; 6:58pm
URL: http://nand2tetris-questions-and-answers-forum.52.s1.nabble.com/Is-there-a-text-editor-trick-to-write-several-identical-lines-of-code-while-incrementing-the-numbers-tp4034607p4034628.html
The way I'd do this is by just opening up my browser's development console (F12) and using a script. I'm not aware of any way to do this within any text editor, though the ability to have multiple cursors can make it less painful.
Chrome has a builtin function available in the devtools called copy.
Example:
copy(Array.from({ length: 10 }, (_, idx) => `Bit(in=in[${idx}], load=load, out=out[${idx}]);`).join('\n'))
Output:
Bit(in=in[0], load=load, out=out[0]);
Bit(in=in[1], load=load, out=out[1]);
Bit(in=in[2], load=load, out=out[2]);
Bit(in=in[3], load=load, out=out[3]);
Bit(in=in[4], load=load, out=out[4]);
Bit(in=in[5], load=load, out=out[5]);
Bit(in=in[6], load=load, out=out[6]);
Bit(in=in[7], load=load, out=out[7]);
Bit(in=in[8], load=load, out=out[8]);
Bit(in=in[9], load=load, out=out[9]);