Tuesday, September 25, 2012

Fix the Home and End keys on Mac OS X

If you use a keyboard that's not designed specifically for Macs, you probably are familiar with the annoying mapping of the Home and End keys: they scroll to the beginning or end of an entire document, with no regard to the cursor's location.

Fortunately it's an easy fix. (Note: This works for native Cocoa apps only, not X11 programs.)

To get your Home and End keys working properly on Mac OS X (Tiger and up, including Mavericks), simply open the Terminal and do this:

$ cd ~/Library
$ mkdir KeyBindings
$ cd KeyBindings
$ nano DefaultKeyBinding.dict

Put these lines in that file, including the curly braces:

/* Remap Home / End keys to be correct */
"\UF729" = "moveToBeginningOfLine:"; /* Home */
"\UF72B" = "moveToEndOfLine:"; /* End */
"$\UF729" = "moveToBeginningOfLineAndModifySelection:"; /* Shift + Home */
"$\UF72B" = "moveToEndOfLineAndModifySelection:"; /* Shift + End */
"^\UF729" = "moveToBeginningOfDocument:"; /* Ctrl + Home */
"^\UF72B" = "moveToEndOfDocument:"; /* Ctrl + End */
"$^\UF729" = "moveToBeginningOfDocumentAndModifySelection:"; /* Shift + Ctrl + Home */
"$^\UF72B" = "moveToEndOfDocumentAndModifySelection:"; /* Shift + Ctrl + End */

Press Ctrl+O and then Enter to save the file, and Ctrl+X to exit. Restart your computer to have it take full effect.



  1. Including the currly braces or no?

  2. Thanks, this worked but then I went to add some additional customizations to mimic the windows "CTRL + [ARROW KEY]" and after reboot it stopped working. So I removed my customizations and refollowed the steps above but now it won't work. Any idea what I might have done?

    1. Sorry, I don't know. Maybe one of the authors at either of the linked blogs could tell you better.

  3. I figured it out, it's worth mentioning here that this only works with cocoa apps, which the Eclipse IDE and Firefox are not. Thanks for posting this!