Thursday, February 19, 2009

Vi Like direction keys for Cocoa apps

Inspired by this post on hacking your key bindings I decided to implement Vi like direction keys for OS X.

Since option is a character modifier usually, and for me at least produces useless characters in combination with j-k-l-i keys, the option key is a good modifier key.

Put the following in ~/Library/KeyBindings/DefaultKeyBinding.dict (create the file if it doesn't exist):


{
/* vi move left */
"~h" = "moveLeft:";
/* vi move down */
"~j" = "moveDown:";
/* vi move up */
"~k" = "moveUp:";
/* vi move right */
"~l" = "moveRight:";
}


Note that you have to relaunch the application before any changes take affect.

What key mappings do you guys use?