Mac OS X and Home / End keys

March 24, 2005

Reading time ~1 minute

The default key bindings for the home and end keys in Mac OS X are different to any other operating system I’ve ever used. By default, they seem to be bound to the viewport, rather than the line of text you are editing. In a multi-line document, the Home key scrolls up to the top of the document, and the End key scrolls down to the bottom. In each case the caret stays where it was.

As a programmer I find this behaviour to be just plain wrong— I want Home and End to move to the start and end of the current line.

I have found a way to “fix” this problem by editing the default keybindings file, ~/Library/KeyBindings/DefaultKeyBinding.dict. Create the directory and / or the file if they’re not already there, and make it look like this:

{
        /* Remap Home / End to be correct :-) */
        "\UF729"  = "moveToBeginningOfLine:";                   /* Home         */
        "\UF72B"  = "moveToEndOfLine:";                         /* End          */
        "$\UF729" = "moveToBeginningOfLineAndModifySelection:"; /* Shift + Home */
        "$\UF72B" = "moveToEndOfLineAndModifySelection:";       /* Shift + End  */
}

If there are already entries in DefaultKeyBinding.dict, just add the 4 new mappings above to the main section of your file.

The Lexus LS600hL RSR

I bought a new car! After 12 years I'm driving a Lexus again. Back in 2011I sold my lovely LS400 to buy a Prius, and I sold the Prius in ...… Continue reading

MINI F54 (Clubman) rear seat repair

Published on June 12, 2017

LS400 ride height sensor repair

Published on November 23, 2009