An Easy VimGolf in Emacs Challenge

Here’s an interesting VimGolf challenge. As they say in the challenge, it’s a simple problem but they’re looking for interesting solutions. The challenge is to turn this

app.config['CHALLENGE_FOLDER'] = SOLUTIONS_FOLDER
app.config['SOLUTIONS_FOLDER'] = CHALLENGE_FOLDER

into this

app.config['CHALLENGE_FOLDER'] = CHALLENGE_FOLDER
app.config['SOLUTIONS_FOLDER'] = SOLUTIONS_FOLDER

The obvious solution that any Emacs user would think of does the job in 81 keystrokes.

Ctrl+s = cursor to =
Ctrl+k kill after =
Ctrl+n down one line
Ctrl+y insert ␠SOLUTION_FOLDER
Ctrl+k kill rest of line
Ctrl+p up one line
Ctrl+y insert ␠CHALLENGE_FOLDER

The best Vim solutions also do it in 8.

What I really want to do is something along the lines of

Ctrl+s = Ctrl+s Mark rectangle
Ctrl+x r k Kill rectangle
Ctrl+x Ctrl+t Swap lines
Ctrl+< Beginning of buffer
Ctrl+x r y Yank rectangle

that’s 12 keystrokes, 50% more than the obvious solution. If I use CUA Selection Mode (as I wrote about previously) I can do it in 9 with essentially the same method as above. Is there a clever way of doing this or is the obvious solution with 8 keystrokes the best we can do? If you can beat 8 keystrokes—especially if it’s something clever—be sure to leave a comment.

Update: Fuco does it in 6.

Update 2: Fuco shaves off another keystroke to a total of 5. Definitely a heavy weight contender.

Footnotes:

1 Using our usual rules of changing the text but not saving the buffer.

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