Skip to content

Configure Home/End Key Bidings on Mac OS X

September 11, 2009

Hi I feel that this  a prety common request: Bind the Home/End keys to move to the beginning and end of lines respectively.

In Mac OS X (10.5 and 10.6) some applications use the Cmd-Rigt and Cmd-Left to perform these actions but, call me old fashioned, I like to use Home and End instead.

It is actually very easy to change the Cocoa Key bindings for any user under Mac OS. Just follow these steps:

  1. Create a file called DefaultKeyBinding.dict in ~/Library/KeyBindings directory
    mkdir ~/Library/KeyBindings
    cd ~/Library/KeyBindings
    touch DefaultKeyBinding.dict
  2. Edit your DefaultKeyBinding.dict file so it contains:
    {
    /* home */
    "\UF729"  = "moveToBeginningOfLine:";
    "$\UF729" = "moveToBeginningOfLineAndModifySelection:";
    
    /* Cmd-Left */
    "@\UF702"  = "moveToBeginningOfLine:";
    "$@\UF702" = "moveToBeginningOfLineAndModifySelection:";
    
    /* Cmd-Right */
    "@\UF703"  = "moveToEndOfLine:";
    "$@\UF703" = "moveToEndOfLineAndModifySelection:";
    
    /* end */
    "\UF72B"  = "moveToEndOfLine:";
    "$\UF72B" = "moveToEndOfLineAndModifySelection:";
    
    /* page up/down */
    "\UF72C"  = "pageUp:";
    "\UF72D"  = "pageDown:";
    }
  3. Restart the Cocoa Application.

This example works very well with TextMate.

In order to bind other keys you need to find their Scan code, and you can use the following modifiers
For more information please check this article

About these ads
12 Comments
  1. Ivan permalink

    what does ~ mean in your path ~/Library/KeyBindings ? If I’m looking up how to get those keys to work you’d think I have the most basic problems on a mac to start with and then using ~ to fill in some directory that first time users have no clue what it is not so helpful.

  2. syonidism permalink

    okay hey, apparently ive done this trick on my mac pro but forgot and ive used my mbp for quite some time and use the cmd+left and cmd+right A LOT. however i cant get my mac pro to register those commands. Is there an easy way to reset every binding or something?

    thanks a lot.

    • pete permalink

      I am still not getting it. Can you provide point by point instructions for activating Home/End keys, i would appreciate it. They do work in Outlook by using ALT + left/right arrows as someone pointed out but it’s not the simple as Home/End. Thanks for your help (I hope). I am using Mt. Lion with Office for Mac and a Microsoft 3000 keyboard. PS: the Genius bar is clueless about this feature.

      • Brian permalink

        Hi Pete. Referring to steps one through three in the original post, you can do Step 1 using the Terminal application and Step 2 using TextEdit. (Both of those programs come standard on the Mac.)

  3. Mark permalink

    I just applied this little “patch” and it works perfectly fine! I just want to thank you, it’s great!!

  4. Jared permalink

    Thank you for the tip, worked perfectly for me in Sublime Text 2 on Mountain Lion.

  5. @JTLai permalink

    Works great on Mountain Lion + my Microsoft ergo 4000 keyboard. Thank you!

  6. Dave Stevens (@daverstevens) permalink

    You just made me a very happy person. I found this while trying to solve the same problem by modifying a keyboard layout. This is much easier though.

    Thanks!

  7. Bill permalink

    Thank you!

Trackbacks & Pingbacks

  1. Usando Home e End para mover para o início e final da linha | iSengardian
  2. Quora

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: