Nothing in this world makes less sense then how Apple decided to make Home, End, Page-Up, and Page-Down work.

I’m not sure where, when, and why this started. But on every other modern day operating system, these keys work like this:

- Home -> move the cursor to the beginning of the line
- End -> move the cursor to the end of the line
- Pg-Up -> move the cursor up the length of the viewport
- Pg-Dn -> move the cursor down the length of the viewport

Now I don’t know why I am even repeating these descriptions. As much as the sky is blue and earth is below our feet, everyone knows what these buttons do.

Unless you are on a Mac. Apple in its infinite wisdom decided this wasn’t a good idea. These buttons don’t make any sense if you have a one button mouse, so let’s make them useless!

- Home -> move (nothing, not even the cursor, just your view) to the beginning of the DOCUMENT
- End -> move (nothing, not even the cursor, just your view) to the end of the DOCUMENT
- Pg-Up -> move (nothing, not even the cursor, just your view) up the length of the viewport
- Pg-Dn -> move (nothing, not even the cursor, just your view) down the length of the viewport

Now, just the fact alone that you can’t, with a single key press, move the end of the sentence is beyond me. Who the hell would want to do that?! But ALSO, the cursor doesn’t move with the view port. So if you find something interesting as you are paging around, you can’t edit it without brining your one button mouse over. Some how, I am reminded of a conversation in “Dude, where’s my car?”

“DUDE! SWEEET!”

Now, maybe that wasn’t the exact conversation Steve Jobs had with himself when he thought of that “feature.” But at most it was replaced with “GNARLY!”

What’s so absurd about this is how no one ever complains about it. I mean, giving this behavior to these buttons essentially renders them USELESS! I can’t believe there are so many people out there that just look at these four buttons and say, “What the heck is that! I’m not using THEM!” Because if you did use them, you would realize how terrible the behavior is.

At any rate, at least Apple designs great software. You can change this absolutely idiotic behavior by editing some local preferences. Here is how:

1. Create a new text file at:

Users/[your username]/Library/KeyBindings/DefaultKeyBinding.dict

(If you have already messed with key bindings, this file might already be present.)

2. Copy and paste this code into the file:

{
    "\UF729"  = "moveToBeginningOfLine:";
    "$\UF729" = "moveToBeginningOfLineAndModifySelection:";
    "\UF72B"  = "moveToEndOfLine:";
    "$\UF72B" = "moveToEndOfLineAndModifySelection:";
    "\UF72C"  = "pageUp:";
    "\UF72D"  = "pageDown:";
}

3. Put your junk in that box (err, save DefaultKeyBinding.dict)

4. Open that box (err, close and reopen any applications to take affect)

That’s it!

Terminal

You must setup mappings in Terminal separately. Open up preferences for Terminal.app, and under the Keyboard tab, set the actions for the following keys (Change action to ‘Send string to shell’):

\033 is the code for escape. Press the Esc key rather than typing it out.

Key		Escape Sequence
Home		\033[1~
End		\033[4~
Page Up		\033[5~
Page Down	\033[6~

Setting up terminal only gets you part of the way. You also need to configure bash. Go create or edit ~/.inputrc and add the following:

"\e[1~": beginning-of-line
"\e[4~": end-of-line
"\e[5~": history-search-backward
"\e[6~": history-search-forward
"\e[3~": delete-char
"\e[2~": quoted-insert
"\e[5C": forward-word
"\e[5D": backward-word
"\e\e[C": forward-word
"\e\e[D": backward-word
set completion-ignore-case On

Now everything should be working the way you expect. (Except for Firefox, but you can figure that one out on your own.)


Disclaimer:

- I am a Mac, Windows, and Linux user
- On the whole, Apple is usually pretty good about this crap.

About the Author:

Learned something? Need help on your dev project? Well, I'm available for hire on project work:

  • Front End Development (jQuery, ExtJS, Backbone)
  • iOS Development
  • Server Side Development (Java Stack or Rails Stack)
  • System Architecture

Contact me:

Discussion

  1. Anonymous says:

    Thanks for the great tip! I’ve been using DoubleCommand for a while to make home and end work properly:

    http://doublecommand.sourceforge.net/

    I acutally now use a combination of DoubleCommand and the DEfaultKeyBindings trick above (using keybindings just for the pgup/pgdown behavior)

    The key setting in DoubleCommand is “PC style home and end keys”. This little plugin is also indispensable if you use a windows style keyboard (I use an MS natural KB) and still want to have option/command in the right places.

    I use Eclipse as my main IDE, and since it’s not a Cocoa app it won’t honor the key bindings. However, it already has the sensible behavior for page up and page down, so all you have to modify to make Eclipse work well is the home and end keys. By setting the home and end keys in DoubleCommand, and mapping pgup/pgdown in the default keybindings, you make the home and end key work properly everywhere, and pgup/pgdown work correctly in cocoa apps.

  2. Anonymous says:

    I’m a new Mac’r… I’m on 10.5.x and this didn’t work on Terminal. bummer..

    There is an option in preferences to remap the home key, but you can only remap it to a keystroke, not BeginningofLine.. I tried setting it to Ctl-A, but I use screen from time to time and the default binding for screen control is Ctl-A..

    This is certainly one of the more frustrating things about OSX..

  3. Anonymous says:

    Thank you so much- this has really been driving me crazy about our new Mac!

  4. Dallin Smith says:

    Thank you so so much! This has always driven me crazy and as a coder – I’m using those keys constantly when programming. This was always my number one complaint about Macs. I never dreamed there would be a solution this easy! Thanks SO much!

  5. Adam Becker says:

    Hey, thanks for this tip. I have always been annoyed by this and finally after five years decided to research it on Google. Great tip, thanks.

  6. nanreh says:

    thanks for writing this, i’m a linux user working on a mac and this home/end behavior has been driving me fucking crazy.
    also:
    * i really wish osx would maximize windows to take up the full screen.
    * i really wish i could activate windows by hovering over them.
    * would be cool if if the osx clock would show date and time, not just day of week and time.
    * how about another mouse button instead of a stumpy mouse and cereal box decoder ring?
    i’ll stop… but my list goes on.
    anyhow, thanks again for helping me fix this major pain point!

  7. Eric says:

    Worked perfectly. I agree 100% with your sentiments…

  8. mk says:

    DoubleCommand does this well. You know what else is driving me crazy? The fact that when I plug in my Logitech keyboard, the Cmd and Option keys get switched!!! WTF.

    So now, the start-key and is the cmd key (even though, on the keyboard itself, the icon shows “alt option” as well as the windows icon), and the Windows “Alt” key is now the “alt option” key, even though it’s labeled with the “Apple” and the “Command” icons.

    But anyway, DoubleCommand fixes all that even though I have to undo my changes every time I take my laptop with me. ARGH!!!

    • Peter Jenkins says:

      @mk You know there’s separate settings for modifier keys in System Preferences for the laptop keyboard and for each external keyboard, right? You can switch the modifier keys however you want, independently, for each keyboard you use.

      Your gripe should be just a matter of modifying System Preferences -> Keyboard -> Modifier keys (make sure the correct keyboard is selected at the top). Unless I’m misunderstanding.

      @Mike Very helpful post, thanks.

  9. Mike Rofone says:

    You, Sir, just won one Internet!

    Now I just need to find out how to make Ctrl+Backspace to do what it sensibly should do – delete the last word instead of the whole line (and WITHOUT bypassing the Undo-feature… seriously, wtf?!?!)

    Thanks!

  10. fat.hamster says:

    it don’t work in xcode :’-(

    i hate f**** mac&apple

  11. Nicolas says:

    Thanks, you made my day !

    I tried DoubleCommand too, but apart from the confusing UI (I’d rather edit a file than using with dang checkboxes), there is no option to get a sane behaviour for page up / page down keys.

    Regards,
    Nicolas

  12. Raoul says:

    I agree, OS X has many annoying things… and this is another one.

    In Eclipse, the behaviour of these keys has to be configured under Settings->General->Keys.

    Now I’ll try to fix it in Qt creator…

    Thanks for this post…

  13. Ryan says:

    This fix didn’t work for me on Mac leopard 10.5. I am going to throw my computer out the window and tell my boss “It broke”.

    • Adam says:

      It didn’t work for me either on an iMac OS X 10.7.1.
      Created the file and directory in two places! One for the root user and one for my account… restarted the apps, the mac… Nothing!
      With all the positive feedback from the users for whom it worked frustration hit the roof… Darn..

  14. Ivan says:

    It doesn’t work in Flash Bulder 4.5 :(

  15. Fernando Madruga says:

    A million thanks!

    This was driving me crazy on XCode 4.2 running on MacOSX 10.6.8 and this fixed it!

    Thanks again!

  16. Seriously says:

    I was forced on a Mac months ago. Thanks for posting this. I cannot for the life of me figure out what was going through their head. However, I’ve used all platforms as well but, I still think M$ Windows 7 has apple beat on UI efficiency. Another thing that totally pisses me off is having to have ui elements in focus before you can interact with it. So, now I can really double the time to carpal tunnel. Thanks again!

  17. John McT says:

    Fantastic. I was about to snap the Home, End, PgUp and PgDn buttons off the keyboard as I was pressing them and getting the wrong results. At work I switch between UNIX and Mac hourly and the non-standard actions were just WRONG.

  18. Matt says:

    No dice on 10.7.

    Oh well, the keys pop off pretty easily using a butter knife.

    • Love_My_Mac_BUTTT says:

      I’ve been using my Mac now for six years and I’m totally surprised that this is NORMAL?!?!? Apple is the epitome of stuck up. They have a great products but it’s just inconceivable how defiant they are at implementing change to the simplest form. There is NO REASON the keys on keyboards shouldn’t work exactly the same as every other computer. This is 2012!!!!!!!

      Anyhow, done with my ranting. Stupid Apple….

      Here’s a great reference on Wikipedia. It’s a comparison chart of keyboard shortcuts between Windows, Mac, and Linux. Although it may not “solve” the dumb-ass buttons on the keyboard that don’t actually do what they say. It will give you an idea of what buttons will.

      http://en.wikipedia.org/wiki/Table_of_keyboard_shortcuts

      If the link I post doesn’t show up a quick Google search of: ‘Table of Keyboard Shorts Windows Mac’ should get you there.

      How can we convince Apple to just give up on this battle with Windows and follow a STANDARD. Keyboard input should not be this complicated in this modern age?!?

  19. Liz says:

    Thanks for this great piece of advice!

    Just wanted to mention that I had no folder called “KeyBindings”, but I used “Keyboard Layouts” which worked fine as well.

  20. Brett Donald says:

    Bravo! Works perfectly under Xcode on Lion

  21. Anonymous Nicholas says:

    Doesn’t work on 10.8.2.

  22. Alejandro says:

    Doesn’t work in OSX Mavericks aka 10.9

    But then, it’s been 6 years..
    If I find how to remove this idiotic behaviour, I’ll post the link here.

  23. My migration back to apple land (after being away for sooo long) now feels complete, thanks to this how to. Now I understand why my mac friends would complain that the end key was useless, when in fact I use it hourly to great effect.
    THANKS!

  1. [... Nothing in this world makes less sense then how Apple decided to make Home, End, Page-Up, and Page-Down work. I'm not sure where, when, and why this started. But on ...]

  2. [... Nothing in this world makes less sense then how Apple decided to make Home, End, Page-Up, and Page-Down work. I'm not sure where, when, and why this started. But on ...]

Leave a Comment