comments Written By: Scott Jangro
August 31, 2006

Fixing OS X Cursor Movement Keystrokes

I’ve been using a Macintosh Powerbook G4 for going on 4 years now. I don’t miss Windows for a second. I’m not even dying to get a new Intel Mac so I can run Windows (though I am dying to get one for the performance improvements).

There are a few things that annoy me about OS X, however. The first being how difficult it is to manage files with the Finder. But that’s for another entry.

The second thing that bothers me every single day is the poor cursor movement via keyboard. I’m a keyboard navigator from way back. I learned how to use Windows 3.0 (yes three-dot-ZERO back in 1990) without a mouse. Again a story for another entry.

Even after 4 years, my fingers still try move the cursor around and select text using the shift and control arrow keys that Windows uses. The alternative on OS X are just not intuitive (or existant?), at least to me.

Maybe it’s the years I spent in Windows, but I just think they got it right. I want home to go to the beginning of the line, end to go to the end of the line. Control-left and right to jump by word, and if I’m holding down the shift-key, those things select the text. Jumping to the beginning and end of the document is not something that I do all the time. So I’m perfectly happy to have those hidden behind key combinations.

I just discovered, however, that the ability to fix all this has been right under my nose for all these years.

OS X allows complete control over the key bindings. By remapping some keys, I’ve been able to get the functionality that my fingers try to do automatically. This methods affects text objects in Cocoa applications.

The default key bindings are stored in:
/System/Library/Frameworks/AppKit.framework/Resources/StandardKeyBinding.dict.

This file is XML, and since you can override them in another file, you probably shouldn’t edit this.

Here’s the quick, no frills, way to get Windows-esque cursor control in OS X.

1. Create this file if it doesn’t exist:

~/Library/KeyBindings/DefaultKeyBinding.dict

(That ~ means “current user”, so you’ll have to do this for each user on the system.)

2. Insert the following code:

{
"^\010" = "deleteWordBackward:";
"\UF729" = "moveToBeginningOfLine:";
"^\UF729" = "moveToBeginningOfDocument:";
"$\UF729" = "moveToBeginningOfLineAndModifySelection:";
"$^\UF729" = "moveToBeginningOfDocumentAndModifySelection:";
"\UF72B" = "moveToEndOfLine:";
"^\UF72B" = "moveToEndOfDocument:";
"$\UF72B" = "moveToEndOfLineAndModifySelection:";
"$^\UF72B" = "moveToEndOfDocumentAndModifySelection:";
"^\UF702" = "moveWordBackward:";
"^\UF703" = "moveWordForward:";
"$^\UF702" = "moveWordBackwardAndModifySelection:";
"$^\UF703" = "moveWordForwardAndModifySelection:";
"\UF72C" = "pageUp:";
"\UF72D" = "pageDown:";
"^z" = "undo:";
"$\UF728" = "cut:";
"$\UF746" = "paste:";
"^\UF746" = "copy:";

/* these allow up and down selecting of text when holding the ctrl key */
"$^\UF700" = "moveUpAndModifySelection:";
"$^\UF701" = "moveDownAndModifySelection:";

}

3. Save the file. You need to restart each application for it to see the changes. Go ahead and try it.

It’s nothing short of a miracle.

It was almost too late. I just realize now that I’m paying attention and that I have these key bindings back in my life that to do things like move to the end of the line, I’ve been hitting down-arrow, left-arrow. This was a crisis!

Much thanks to Llew Mason (link below) for the above bindings. In the spirit of pay-it-forward, I added my own two at the bottom and now share this with all my Mac-using friends who may have not stumbled upon this yet.

If you’re looking for more advanced options, other key codes, etc., check out the websites below.

Resources
Much thanks goes to the following websites which clued me into this possibility in the first place, and document this process in much more detail:

Llew Mason’s Mac OS X Key Bindings
TextMate Blog: Key bindings for switchers

If you enjoyed this post, please subscribe to my RSS feed

1 Comment... What do you think?


  1. Jordan Glasner said on October 4th, 2006 at 12:13 pm

    The default bindings for everything excep home/end are pretty similiar.

    Control arrow = end of line in that direction
    Option arrow = word in that direction

    Hold shift to select text just like Windows.

Join the discussion by leaving a comment...

How do I change my avatar?

Go to gravatar.com and upload your preferred avatar.