How to Escape a Viper

January 21, 2009

This is kind of a dumb post.* I like to use the viper package for emacs, which mostly works just fine.  I’m in the habit of using C-[ (hold-down control, press '[') instead of <escape> to back into command mode.

Sometimes I run emacs on Mac OS X (be it a Carbon port, in X11, or through a terminal).  Unfortunately, various Mac-compatible emacsen interpret C-[ as Meta and not as <escape>.  So instead of backing into command mode, I see "ESC-" at the bottom of the screen.  I can wait forever and emacs will never parse it into an <escape>.  If I try again, I see "ESC-ESC-".  If I try a third time, the command completes but does nothing, except causing me to scream in agony since I'm still not in command mode.

Fortunately I found that adding a simple (setq viper-ESC-key "^[") to my ~/.viper, where '^[' is literally the <escape> character (i.e., ASCII 27)**, fixes everything (viper-ESC-key is set to "\e" by default, which is supposed to be <escape> but whatever).

And there you have it.

* ... but this took me months to figure out.  I'm posting this so that maybe someone searching for "mac os x emacs meta escape viper fails" finds the help they need...

** If you're editing in emacs, type C-q C-[ to get a literal '^]‘.  If you’re editing in vim, type C-k C-[ to get a literal ‘^[‘.

Tags: , ,

Leave a Reply