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.

Advertisements