Mac OS X Home and End Keys

Posted on
Tags: , ,

Update: Now you can skip all these instructions and just download my KeyFixer application to fix your home and end keys. Read the new article ...

The default behavior of OS X's "home" and "end" keys drives me nuts. In every other operating system that I've used, these keys move your cursor to the beginning (home) or end (end) of your current line. Thankfully, Dreamweaver on the mac behaves this way, but everything else behaves oddly (usually moving you to the beginning or end of the entire document, and sometimes moving just the focus, while leaving the cursor in place).

Today, I decided to try to change this default behavior, and thanks to this blog post by Jon Evans, it was easy. Thanks for the tip Jon!

Update: If the files don't already exist, you need to create them. Here's the easy way to do it in Terminal (easier, because Finder doesn't let you see hidden files easily).

Open Terminal (Applications -> Utilities -> Terminal) and type the following commands:

cd ~/Library/

then

ls

Now, if you don't see the KeyBindings folder, type

mkdir KeyBindings

Go into the KeyBindings Directory

cd KeyBindings

Make or Edit DefaultKeyBinding.dict

nano DefaultKeyBinding.dict

This opens the nano text editor. Paste these lines from the tutorial in into the file.

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

I also did some seaching and found this article on the TextMate blog. The following lines from that article add a "fix" for the page up and page down keys.

{
    /* home */
    "\\UF729"  = "moveToBeginningOfLine:";
    "$\\UF729" = "moveToBeginningOfLineAndModifySelection:";


    /* end */
    "\\UF72B"  = "moveToEndOfLine:";
    "$\\UF72B" = "moveToEndOfLineAndModifySelection:";


    /* page up/down */
    "\\UF72C"  = "pageUp:";
    "\\UF72D"  = "pageDown:";
}

press control-x to exit (make sure you save the file).

Now, you don't need to restart OS X, just any applications that you want to use the new KeyBindings in. Remember, this still doesn't work right in Firefox. Also remember that you're changing system setting (in this case, just for the user you're logged in as) and you should always be careful when making system changes :)

comments powered by Disqus