Posts Tagged ‘linux’

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 ‘^[‘.

hlsearch for Emacs

September 19, 2008

Vim has an option called “hlsearch” that highlights every instance of your most recent search term.  Like this:

Searching for "ground" in a text document using Vim.

Searching for "ground" in a document using Vim.

Emacs has the viper and vimpulse plugins that closely emulate vi/vim keyboard commands, but no hlsearch.  If you’re using viper and a version of Emacs later than 22.0, pasting the following into your .viper will give you this functionality.

(defun viper-flash-search-pattern ()
  (hi-lock-mode 0) (hi-lock-mode 1)
  (hi-lock-set-pattern
     (car viper-search-history) 'hi-green)
)

Unfortunately toggling hi-lock mode (line 2) is destructive if you’re using hi-lock mode for anything in addition to highlighting search terms.  In other words, there’s probably a better way to write this function. To solve the problem of clearing highlighting I’m no longer using, I use this (inefficient) snippet:

(viper-record-kbd-macro "//"
  'vi-state
  [(meta x) h i - l o c k - m o d e (control m)
   (meta x) h i - l o c k - m o d e (control m)]
't)

Ratpoison

February 28, 2008

Ratpoison logoA Window Manager, commonly abbreviated wm, is a program that controls the way your windows appear and behave. A good wm can be likened to an operating system: it provides a necessary service, but you barely know it’s there it because it doesn’t get in the way.

ratpoison is founded on the (apparently drug-induced) notion of a window manager that doesn’t get in the way. It does this by being constraining, inflexible, and primitive.

Read the rest of this entry »