the power of q

I tend to use vi/vim quite a lot and have grown from hating it, to enjoying it like a cracked filling: I can’t help but poke at it and am always startled by the results. Today, I learnt about a command that makes all of the others seem tame:


Wow. It starts recording and will then playback the results, which might sound tame but has just turned an hour and a half of work into 60 seconds of jaw dropping fun. I have a program file where I want to trace the function call route, and for reasons I shan’t explain the easiest way to do this is to place a print statement at the start of each function, and then simply watch until the program dies. Mind you, this is in Forth so print is in fact ." but to do this over a 144KB text file with over 150 functions is tedious. However, all of the functions start the same way, with a bracket, number and then a comma, so armed with that, the keystrokes are:

qa/^: (\d,
xi."<ESC>A" cr<ESC>q

Simple ! Now all I have to do is type @a to get it all to work, but that’s not the end of it: @a behaves just like any other command, so prefix it with a number, eg: [email protected] and 100 functions have just had a trace print added !

I’m so happy – serious vim users are welcome to point and laugh, I don’t care at the moment 🙂

Comments are Disabled