Let’s Play Ivmgolf

After my last VimGolf post I thought it would be fun to try another so I headed over to the VimGolf site to find a challenge. The first one I stumbled across was Let’s play some Imvgolf. The challenge is simple: starting with

Ivm is an awesome text editor based on
Iv, and is used to play a game called
Ivmgolf. A challenge, simple for many
Ivmgolfers, can still hide secrets.

transform it to

Vim is an awesome text editor based on
Vi, and is used to play a game called
Vimgolf. A challenge, simple for many
Vimgolfers, can still hide secrets.

in the smallest number of keystrokes possible.

My first thought was that it was too simple. Surely, it would hard to beat a simple query-replace: 【Meta+%ivReturnviReturn】 【!】 for a total of 8 keystrokes. Hard to see how you could do much better than that. Except that the winning VimGolf entries solved it in only 5 keystrokes1

Using Magnor Sveen’s awesome multiple-cursors package, which should and probably will be part of Emacs core, I was able to get that down to 6 keystrokes.

It’s easy to see what you need to do: switch the first two characters of each line and adjust the capitalization. I tried that using keyboard macros and even apply-macro-to-region-lines but I couldn’t do better than query-replace using core Emacs functionality. The problem is that any macro that requires typing in Vi has already used 4 keystrokes, and if you use a macro and something like 【Ctrl+t】 to switch characters you’ve used 3 keystrokes and still have to adjust the capitalization, get to the start of the next line, and run the macro on the rest of the lines. If you can do better than 8 keystrokes with stock Emacs, be sure to leave a comment.

Footnotes:

1 The VimGolf rules say you have to save the file too so that adds an extra 2 keystrokes in both Vim and Emacs but I’m ignoring them since they add nothing useful to the challenge. All scores in this post are without saving the file.

This entry was posted in General and tagged . Bookmark the permalink.