Key Bindings
03 May 2006
A feature I love about Mac OS X is the fact that key bindings are consistent across applications. Once your fingers learn apple-s for save, apple-q for quit, etc., you become much faster. The default cursor movement keystokes, however, are awkward: apple-rightarrow jumps to the end of the line, apple-leftarrow jumps to the beginning of the line, option-rightarrow and option-leftarrow skip by word. I don't like the fact that I have to move my right hand out of home position to use them. Users of UNIX systems are familiar with another convention, emacs-style key bindings, and these can be easily enabled on Mac OS X.
The secret is a file called DefaultKeyBinding.dict
in ~/Library/KeyBindings
. By default, neither the file nor the directory will exist. You need to create the file, put it in ~/Library/KeyBindings
, and reboot (or logout). Here is my DefaultKeyBinding.dict
file:
/* ~/Library/KeyBindings/DefaultKeyBinding.dict */
{
"~f" = "moveWordForward:";
"~b" = "moveWordBackward:";
"~<" = "moveToBeginningOfDocument:";
"~>" = "moveToEndOfDocument:";
"~v" = "pageUp:";
"~d" = "deleteWordForward:";
"~^h" = "deleteWordBackward:";
"~\010" = "deleteWordBackward:"; /* option-backspace */
"~\177" = "deleteWordBackward:"; /* option-delete */
"^e" = "moveToEndOfLine:";
"^a" = "moveToBeginningOfLine:";
"^u" = "deleteToBeginningOfLine:";
"\033" = "complete:"; /* Escape */
}
Now you have the following KeyBindings (and others):
ctrl-a | jump to beginning of line |
ctrl-e | jump to end of line |
option-f | skip forward by word |
option-b | skip backward by word |
ctrl-u | delete to beginning of line |
option- | delete delete backward by word |
These key bindings work in all Cocoa applications that use the standard text editing tools. For example, here’s something I do all the time:
- Drag a folder from Finder to Terminal
- type
ctrl-a
to skip to the beginning of the line - type
cd
and press enter