Joachim Breitner's Homepage
The problem with turing complete editors
I was just editing a file with vim and was about to do the same few strokes repeatedly. I vaguely remembered something about recording macros, so I tried it: I pressed q-1 to start recording, did my steps (a yank, a movement, an insert, a paste, a movement), and finished the recording with q. Now I could repeat these steps with @-1.
I then noticed that I forgot something at the end (moving the curser to the beginning of the line). I re-started recording (q-1), thought “hey, maybe I can insert the old recording here” and pressed @-1. Surprisingly, that worked. I added the missing movement and finshed the recording with q.
When I then tried to recall these commands with @-1, the editor froze and I was wondering whether the network connection went down (I was working over SSH). But it wasn’t, and it dawned me that vim did not insert my old commands when re-recording the macro, but just inserted the call to the macro itself. My text editor was caught in a infinite loop...
Not too bad, I just killed vim, did not lose anything and everything was fine. But I think an editor, even vim, should somehow prevent such behaviour.
Comments
Sometimes it is more convenient to define a mapping instead of a macro -- then when it goes wrong, you can use the command line history to fix the definition without having to redo everything. Although hardcore vimmers do edit macros by pasting them into a buffer, editing, and yanking them back to the same register.
What he neglected to say, though, is that you can *append* to registers a-z by using capital letters.
So after doing the first recording with "qa", you could add the movement to next line with "qA".
:-)
I'm sure I could probably do the same thing in a better way, given that I wasn't as experienced with vim as I am now, but still occasionally useful.
Have something to say? You can post a comment by sending an e-Mail to me at <mail@joachim-breitner.de>, and I will include it here.