Login  Register

Is there a text-editor trick to write several identical lines of code while incrementing the numbers on each line ?

Posted by petafunk on May 08, 2020; 1: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-tp4034607.html

This isn't a problem per se, I'm just asking for a tip if it exists. Sorry if I my explanation is not clear.

I'm going through Week 3 of the projects right now, and there's been several times already where you have to write n times the same line, only increasing the number in the bus addresses :

    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]);
    [...]

It's fine to do it by hand, but it also sounds like something veteran coders would know how to automate.

In other languages than HDL I'd be using a "if" or other kind of loop, but they don't apply here. I'm thinking maybe there's something to do in the text editor itself ? With regular expressions maybe ? I've used them on a couple occasions but I don't handle them well enough to know if this is a possibility.

If it matters, i'm working with Sublime Text at the moment. Thanks for your suggestions.