How to fix home and end keys on Mac OS X

How to fix home and end keys on Mac OS X
Photo by Ilya Pavlov / Unsplash

As a big fan of the Apple full size keyboard, I was constantly bugged by the fact that the home and end keys were not working properly in many apps.

This fix, inspired by this article, enables the keys to work properly everywhere:

Open a terminal:

$ cd ~/Library
$ mkdir KeyBindings
$ cd KeyBindings
$ vi DefaultKeyBinding.dict

Copy/paste the following lines:

{
/* Remap Home / End keys to be correct */
"\UF729" = "moveToBeginningOfLine:"; /* Home */
"\UF72B" = "moveToEndOfLine:"; /* End */
"$\UF729" = "moveToBeginningOfLineAndModifySelection:"; /* Shift + Home */
"$\UF72B" = "moveToEndOfLineAndModifySelection:"; /* Shift + End */
"^\UF729" = "moveToBeginningOfDocument:"; /* Ctrl + Home */
"^\UF72B" = "moveToEndOfDocument:"; /* Ctrl + End */
"$^\UF729" = "moveToBeginningOfDocumentAndModifySelection:"; /* Shift + Ctrl + Home */
"$^\UF72B" = "moveToEndOfDocumentAndModifySelection:"; /* Shift + Ctrl + End */
}

Save the file and restart your computer.

Enjoy your home and end keys!