MacOS – change the behavior of the Home and End keys on an Apple Keyboard with Numeric Keypad

keyboardmacmacos

I just bought an "Apple Keyboard with Numeric Keypad", then I connected it to my Macbook Pro running Lion.

But the home and end key under the F14 key doesn't work as I expected. Say in "Pages", the home key doesn't bring the cursor to the beginning of the line, while the end key takes you to the bottom of the page.

Does anyone know how to re-map the home/end key?

Best Answer

One option is to create ~/Library/KeyBindings/ and save a property list like this as ~/Library/KeyBindings/DefaultKeyBinding.dict:

{
  "\UF729"  = moveToBeginningOfLine:;
  "\UF72B"  = moveToEndOfLine:;
  "$\UF729" = moveToBeginningOfLineAndModifySelection:;
  "$\UF72B" = moveToEndOfLineAndModifySelection:;
}

Quit and reopen applications to apply the changes. Note that DefaultKeyBinding.dict is not supported by some applications like Xcode or Firefox.

In Terminal you can assign home (↖) to control-a and end (↘) to control-e from Preferences > Settings > Keyboard. That will leave you with no key combinations to scroll to the top or bottom of a window though.

It might be easier to just use the default keybindings. In most native text views:

  • control-A or option-up goes to the beginning of a paragraph
  • control-E or option-up goes to the end of a paragraph
  • command-left goes to the beginning of a line
  • command-right goes to the end of a line