Mickey Plays VimGolf In Emacs

I've written a couple of times about Tim Visher's VimGolf In Emacs series of videos. If you're an Emacs user and haven't taken a look at them yet, you should do so without delay. They are very informative and entertaining.

Now Mickey Petersen over at Mastering Emacs has gotten into the act. That makes me very happy because I really enjoy seeing how other Emacs users solve editing problems. I almost invariably learn something useful by watching or reading those solutions. Mickey's take on the problems is a little different from Visher's. He says up front that there's no way Emacs is going to be as efficient in terms of keystrokes as Vim and instead he concentrates on finding a general—or as he says, technically correct—solution. By that he means a solution that works for bigger or smaller data. The problem with VimGolf solutions is that they tend to be crafted for the particular piece of data that's being edited. That's because in order to minimize keystrokes the solution has to be tailored to the specific data in the problem.

The problem that Mickey considers is to sort the following records into alphabetical order by people's names.

## Directory
   * Smith, George
      - 1234 Avenue, New York, NY
   * Bailey, Stephen
      - 4545 Harbor Ln, Atlanta, GA
      - Phone: (412) 291-1238
   * Thomas, Brent
      - 1482 Mystic Oaks, Anaheim, CA
   * Grant, Jenny
      - 198 Circle Dr, Houston, TX
      - Phone: (213) 198-9842
      - Email: jenny.grant@gmail.com
   * Percy, Adam
      - 221 Jaguar Pkwy, Missoula, MT
   * Garfield, Misty
      - 5988 Apple Tree Ln, Memphis, TN
   * Parsons, Betty
      - Phone: (235) 523-2378
      - Email: bettyboop123@gmail.com
   * Sanders, Terry
      - Email: sanderst@yahoo.com
   * Smith, Pete
      - Phone: (294) 984-2938
   * Frost, Jennifer
      - 2498 Temple Terrace, Miami, FL
   * Matthews, Frank
      - 418 Happy Trail, Phoenix, AZ
      - Phone: (985) 129-2394
      - Email: frank@phoenixrealtors.net
   * Allen, Taylor
      - Email: allen.taylor@hotmail.com
   * McCullen, Sarah
      - 247 Hidden Elm, Seattle, WA
      - Phone: (288) 283-4568
   * Perkins, Mike
      - 992 Peartree Ln, Bowling Green, KY

Think for a second or two how you might do that in Emacs and then jump over to Mickey's post to see how he leveraged the power of Org-mode to solve the problem. It's a brilliant solution and with smex installed is probably competitive with the Vim solutions even without trying.

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

5 Responses to Mickey Plays VimGolf In Emacs

  1. Xah Lee says:

    interesting one.

    i thought by replacing to a unicode char than call sort-line does the trick.

    turn on whitespace-mode first to see the invisible chars.
    Replace "\n - " by any unicode symbol, e.g. bullet •
    Now, call sort-line to sort the lines.
    Do replace again to revert.

    For me, the keys are:

    【CapsLock】 【w】 【s】 【m】 【Return】 (turn on whitespace-mode)
    【Alt+Shift+j】 (move cursor to top)
    【Alt+5】 (call query-replace)
    【Ctrl+q】 【Ctrl+j】 【space】 【space】 【space】 【Return】. (insert text to replace)
    【Hyper+3】 【Return】 (unicode bullet char, start replace)
    【!】 (replace all.)
    【Alt+Space】 【Alt+Shift+h】 【↓】 (select all except first line.)
    【CapsLock】 【s】 【l】 (call sort-lines)
    【Alt+5】 (call query-replace)
    【↑】 【Return】 ( text to replace)
    【↑】 【↑】 【Return】 ( replacement text)

    been thinking of doing some video recording... also, some software that shows my keystrokes. Any recommendations or resources?

  2. Phil says:

    A very slightly off-topic comment here. I tried to create a Vimeo account to comment on one of the "VimGolf in Emacs" videos, but "New signups are currently disabled", which is annoying. In episode 11 Tim tackles numbering a list, and although he uses the obvious approach, he ends up with a relatively large count of 13 keystrokes, instead of the 9 in which it can be done using the same basic method. He already beats vim on this one (17 is the best score on the vim leaderboard), but it's a shame to still be so many strokes over (although Mickey would undoubtedly approve of the more general-purpose result of Tim's longer version :)

  3. Phil says:

    My initial solution used the same idea as Xah's, but I can also beat the vim leaderboard with a completely different method:

    C-x h C-n M-x s - r
    - f RET . + \ ( C-q C-j SPC + - . + \ ) * RET
    \ & RET

    28 strokes.

    Not a patch on the 15 for Mickey's, mind (I make that one out as M-x o r g - m o d RET C-x h C-n C-c ^ a) but as a general approach to the basic problem of sorting multi-line entries, it's good (it looks like org-sort fails without those asterisks).

Comments are closed.