I recently decided to take the plunge and buy a new 14" M2 Macbook Pro. The driving force was to do more IOS development, which is a bit more challenging; if not impossible, on a Windows based computer. My normal setup is a laptop hooked up to a larger external display, with a mouse and keyboard (preferrably a mechanical one). The setup isn't exciting or special, and for the most part, works just fine. However OSX doesn't seem to treat external keyboards properly. Almost all the keys work fine, with the exception of HOME and END. Now typically, on a Windows computer, you hit HOME and you go to the beginning of a line, and END would take you to the end of the line... But on OSX, it does not... HOME goes to the top of your document, and END goes to the bottom, which is not very useful, and is mainly annoying. In typical Apple fashion, this is because Apple expects you to NOT use anything other than their own keyboards, which don't have dedicated HOME, END, PAGE UP, and PAGE DOWN keys. They want you to use their FN+Arrow key operations. That's great if you're on their laptop keyboard or using their own keyboard, but not so great for any third party keyboards. So, how do you fix this? After digging around the internet for clues, here is how to fix it:

  1. Open a Terminal Window

  2. Make a new folder in ~/Library called "KeyBindings"

    mkdir -p ~/Library/KeyBindings
  3. In this folder, make a new file called "DefaultKeyBinding.dict"

    nano ~/Library/KeyBindings/DefaultKeyBinding.dict 


    vim ~/Library/KeyBindings/DefaultKeyBinding.dict 

    I prefer vim as my editor, but nano is a bit easier to use for those that aren't familiar with vim.

  4. Paste this into the new file:

/* Remap Home / End keys */

/* Home Button*/
"\UF729" = "moveToBeginningOfLine:";

/* End Button */
"\UF72B" = "moveToEndOfLine:";

/* Shift + Home Button */
"$\UF729" = "moveToBeginningOfLineAndModifySelection:";

/* Shift + End Button */
"$\UF72B" = "moveToEndOfLineAndModifySelection:";

/* Ctrl + Home Button */
"^\UF729" = "moveToBeginningOfDocument:";

/* Ctrl + End Button */
"^\UF72B" = "moveToEndOfDocument:";

/* Shift + Ctrl + Home Button */
"$^\UF729" = "moveToBeginningOfDocumentAndModifySelection:";

/* Shift + Ctrl + End Button*/
"$^\UF72B" = "moveToEndOfDocumentAndModifySelection:";
  1. Save the file, and reboot your Mac.