Implementation of today’s xkcd in Vim

I couldn’t help myself.

In case you haven’t seen it, the xkcd comic for today plays on the weird configurations we programmers apply to our personal computers. The mouseover text reads: “If used with software that could keep up, a scroll wheel mapped to send a stream of ‘undo’ and ‘redo’ events could be kind of cool.” Well, as it turns out, Vim can “keep up.” All it takes is these two commands:

map <ScrollWheelDown> :undo<CR>
map <ScrollWheelUp> :redo<CR>

Put those in your .vimrc or run them as commands and watch as using the scroll wheel or two-finger trackpad scroll cycles through your history. Enjoy!

Fun fact: the comic alludes to mapping caps lock to control, which is something that Emacs users actually do. Vim users are more partial to mapping caps lock to escape.


3 thoughts on “Implementation of today’s xkcd in Vim

  1. It’s also useful to map the Caps Lock to control for using the Eclipse quick actions menu (Ctrl-1), since it’s kind of a pain to regularly make the stretch from left ctrl to 1. In any case remap your caps lock key. It’s just the right thing to do.

    And protip: a better key to use for switching between Dvorak and QWERTY than both shift keys is the right super key. It’s easier to give your family instructions over the phone that way.

    • So you’ve done two of these things, and I’ve done the third (briefly, for the sake of the comic). I guess this comic really is an accurate depiction of programmers. Is the quick actions menu the same as the ctrl-space autocomplete menu? And while we’re talking about mappings, I have jk mapped to Esc in Vim. Mapping caps lock seemed too drastic; I use that key. This way only bugs me when I’m typing “Dijkstra” or the alphabet.

      • Ctrl-1 is not the autocomplete menu, it brings up suggested actions. Try placing your cursor on an error in the code and using it. But it also is fantastic everywhere else. Just try it and get addicted.
        That jk one is cool, of course it would have to be different letters for me…

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s