VimGolf in Emacs: Enumerate Words

Here’s a pretty hard challenge—at least I found it challenging. Given this Lorem Ipsum

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,
no sea takimata sanctus est Lorem ipsum dolor sit amet.

list the unique, capitalized words in alphabetical order:

Accusam
Aliquyam
Amet
At
Clita
Consetetur
Diam
Dolor
Dolore
Dolores
Duo
Ea
Eirmod
Elitr
Eos
Erat
Est
Et
Gubergren
Invidunt
Ipsum
Justo
Kasd
Labore
Lorem
Magna
No
Nonumy
Rebum
Sadipscing
Sanctus
Sea
Sed
Sit
Stet
Takimata
Tempor
Ut
Vero
Voluptua

The winning Vim solutions use 23 keystrokes but the best I can do is 32. My solution:

Ctrl+Meta+% Invoke query-replace-regexp
space Return Replace spaces
Ctrl+q Ctrl+j Return With carriage returns
! In the entire buffer
Meta+< Back to top-of-buffer
Ctrl+Meta+% Invoke query-replace-regexp
[.,]Return Replace periods and commas
Return With nothing
! In the entire buffer
Return Down one line
Ctrl+Return Invoke rectangle mode
Meta+< Extend rectangle to top-of-buffer
Meta+u Upcase rectangle
Ctrl+x h Mark buffer
Ctrl+u Meta+| Pipe to shell and replace
sort -uReturn Sort and delete duplicates

Most of the work involved the two query-replace-regexp calls but I couldn’t figure out a way to do it in one without causing other problems. The call to the external sort may be a technical violation but I’m claiming that we’re grandfathered in by Tim on that.

I think the Vimers did so well because Vim has an internal sort that’s easy to invoke. I’m sure many of you can beat my pathetic 32 so leave a comment with your better solutions.

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