Make Home & End keys behave like Windows on Mac OS X

I’ve been using Mac OS X daily since 2001 when I purchased my Titanium PowerBook and I still can’t get used the home and end key behavior.

If, like me, you want Home to send you to the start of the line and not to the top of the document then create a file called DefaultKeyBinding.dict in your ~/Library/KeyBindings folder (might need to create that folder too) with the following contents:

{
  "\UF729"  = moveToBeginningOfParagraph:; // home
  "\UF72B"  = moveToEndOfParagraph:; // end
  "$\UF729" = moveToBeginningOfParagraphAndModifySelection:; // shift-home
  "$\UF72B" = moveToEndOfParagraphAndModifySelection:; // shift-end
  "^\UF729" = moveToBeginningOfDocument:; // ctrl-home
  "^\UF72B" = moveToEndOfDocument:; // ctrl-end
  "^$\UF729" = moveToBeginningOfDocumentAndModifySelection:; // ctrl-shift-home
  "^$\UF72B" = moveToEndOfDocumentAndModifySelection:; // ctrl-shift-end
}

This remapping does the following in most Mac apps including Chrome (some apps do their own key handling):

  • Home and End will go to start and end of line
  • ShiftHome and ShiftEnd will select to start and end of line
  • CtrlHome and CtrlEnd will go to start and end of document
  • ShiftCtrlHome and ShiftCtrlEnd will select to start and end of document

Note that you will need to reboot after creating this file for it to take effect.

If you have a PC keyboard with LED back-lighting and would like the scroll-lock, num-lock or caps-lock LEDs on when using your Mac check out my free SetLEDs for Mac

[)amien

41 responses

  1. Avatar for Alkirah

    Amazing! Works like a charm on latest el capitan version. Thanks!

    Alkirah – September 2nd, 2016
  2. Avatar for Alex

    For words selection like in Windows can be used next rules:

    ”^\UF702” = (moveWordLeft:); // ctrl-left “^$\UF702” = (moveWordLeftAndModifySelection:); // ctrl-shift-left “^\UF703” = (moveWordRight:); // ctrl-right “^$\UF703” = (moveWordRightAndModifySelection:); // ctrl-shift-right

    Alex – September 30th, 2016
  3. Avatar for Ryan

    This worked on the latest macOS as well. Thank you.

    Ryan – January 26th, 2017
  4. Avatar for Martin

    also works on Version Mac OS X 10.12.4 (16E195). Awesome thanks, I love it :-) Is there some more stuff how to use that? Would love if I can change all my favourite shortcuts in one place

    Martin – May 10th, 2017
  5. Avatar for Shay

    DefaultKeyBinding.dict is ignored by some applications like XCode and Firefox and in some views like in WebKit web inspectors. Also good luck mapping the function key, caps lock (read up on that- a large amount of people want that). I am a left-hand mouser and wanted cut/copy/paste functions with the right hand. Trouble is, you can’t map control+fn (for copy), nor shift+fn (for paste), which are the keys that map positionally on a PC keyboard (I’m talking for PC keyboards with 2 rows of three keys: Ins, Home, Pg UP / Del, End, Pg Down). Another issue is when you are like me, doing lots of Windoz in a VM (Oracle Virtualbox) and remote desktop (Microsoft Remote Desktop for MacOS). There you need to pass different keys so everything works. Same with terminal apps. Karabiner is the go-to tool for key remapping, but there are issues with Sierra (Karabiner-elements is the next thing, but still a work in progress. So, I built something that works in all contexts (ok, almost all) using Hammerspoon, a superb tool for automation on the Mac: https://github.com/quickdraw6906/hammerspoon-pc/blob/master/config.lua

    Shay – November 8th, 2017
  6. Avatar for Ashton Cormallen

    You are using ^ to denote the Ctrl key but how do I denote the Cmd key?

    Ashton Cormallen – December 28th, 2017
  7. Avatar for andyrak

    You can denote the Cmd key with ⌘ (PLACE OF INTEREST SIGN, Unicode: U+2318, UTF-8: E2 8C 98). Hope that helps.

    andyrak – February 27th, 2018
  8. Avatar for Tyler

    It has been SO hard to accept the loss of functionality of the Home/End keys after moving to Mac full time. What a blessing your tip/snippet is! Thanks, Damien!

    -TW

    Tyler – August 3rd, 2018
  9. Avatar for Eric

    Hey, thanks for this! However, I don’t see it working in some apps in Chrome. Any suggestions. - Eric

    Eric – August 7th, 2018
  10. Avatar for Roger Miller

    Yay! Working on MacOS High Sierra

    Roger Miller – August 16th, 2018
  11. Avatar for pale

    Would it be strange if I were to propose to you on the spot?

    I’ve been using PC and Linux since 1997, and just got a Mac to get into iOS development. You saved my efficiency.

    pale August 24th, 2018
  12. Avatar for Brian

    This didn’t work for me on Mojave. I had to use BeginningOfLine instead of BeginningOfParagraph. Here is my file:

    { "\UF729" = moveToBeginningOfLine:; // home "\UF72B" = moveToEndOfLine:; // end "$\UF729" = moveToBeginningOfLineAndModifySelection:; // shift-home "$\UF72B" = moveToEndOfLineAndModifySelection:; // shift-end "^\UF729" = moveToBeginningOfDocument:; // ctrl-home "^\UF72B" = moveToEndOfDocument:; // ctrl-end "^$\UF729" = moveToBeginningOfDocumentAndModifySelection:; // ctrl-shift-home "^$\UF72B" = moveToEndOfDocumentAndModifySelection:; // ctrl-shift-end }

    Brian – March 21st, 2019
  13. Avatar for Jerry Baker

    Nice, works like a charm for High Sierra. By the way, restarting computer isn’t necessary. Restarting finder should be sufficient

    command: killall Finder

    Thanks!

    Jerry Baker April 29th, 2019
  14. Avatar for Jonathan Feinberg

    Yayyy! Working perfectly in Catalina, and Jerry Baker’s suggestion to nuke Finder worked perfectly without a reboot.

    Jonathan Feinberg March 25th, 2020
  15. Avatar for Martin

    Worked for me on Catalina. The default behaviour in Chrome was driving me nuts.

    Many thanks!

    Martin – April 7th, 2020
  16. Avatar for Eric

    You just saved me from hours of agony in quarantine! (MacOS 10.15.4)

    Eric – April 14th, 2020
  17. Avatar for Ross

    Wonderful! This WFH period has really forced me to use my work laptop (mac) as my daily driver (as opposed to a modified Ubuntu at work) and this HOME/END thing was driving me nuts.

    Ross – April 16th, 2020
  18. Avatar for Brian

    This is huge!! Thanks!!

    Brian – April 16th, 2020
  19. Avatar for John

    As other have said this is fantastic. Thank you!

    John – April 22nd, 2020
  20. Avatar for Evey Hammond

    Big thanks for this.

    For those like me, who aren’t regular Terminal users and who don’t just intuitively know what “create a file… [in your library] with the following contents” means: 1)Open Terminal. (Applications>Utilities> Terminal)

    2) Type/copy paste in “mkdir -p ~/Library/KeyBindings/” and hit enter Type/copy paste in “touch ~/Library/KeyBindings/DefaultKeyBinding.dict” and hit enter Type/copy paste in “touch ~/Library/KeyBindings/DefaultKeyBinding.dict” and hit enter

    3) A Notepad window will pop up. Copy-paste Damien’s code into that window and hit save. Here it is again: { “\UF729” = moveToBeginningOfParagraph:; // home “\UF72B” = moveToEndOfParagraph:; // end “$\UF729” = moveToBeginningOfParagraphAndModifySelection:; // shift-home “$\UF72B” = moveToEndOfParagraphAndModifySelection:; // shift-end “^\UF729” = moveToBeginningOfDocument:; // ctrl-home “^\UF72B” = moveToEndOfDocument:; // ctrl-end “^$\UF729” = moveToBeginningOfDocumentAndModifySelection:; // ctrl-shift-home “^$\UF72B” = moveToEndOfDocumentAndModifySelection:; // ctrl-shift-end } Copy

    5) Quit and relaunch apps for this to take effect.

    Evey Hammond – May 6th, 2020
  21. Avatar for FredS

    WFH indeed… I googled again for a solution and reading the instructions I found I had created that file in the past (this issue has been annoying me long already) but it doesn’t seem to work. I have Catalina 10.15.4. Any hint?

    FredS – May 8th, 2020
  22. Avatar for alexrqs

    THANNNNNNK YOU!!

    alexrqs – May 25th, 2020
  23. Avatar for trennor

    “3) A Notepad window will pop up. Copy-paste Damien’s code into that window and hit save. “

    On Catalina, this does not happen and I cannot find ANY way to save this script. “Text”app and Script Writer REFUSE to save it where directed. I’m at the end of my wits here; HOW is this actually accomplished? I’m attempting to save, as suggested, in ~(home/dir) ~/Library/KeyBindings/Default/KeyBinding.dict, but every time i check the file in terminal, it’s empty. What, please, is going on?

    trennor – May 25th, 2020
  24. Avatar for Heinz Hemken

    Yay! Thanks! [Insert lengthy, obscenity-laced vituperation over this and a number of other “natural” MacOS behaviors]

    Heinz Hemken – May 26th, 2020
  25. Avatar for Robert

    Can confirm that Damien’s code plus Evey’s file creation instructions works on macOS Catalina (Version 10.15.5). Thank you both!

    Robert – June 4th, 2020
  26. Avatar for Rob

    WOW. What a difference it makes to have those keys remapped in a sane way. I gotta wonder what the heck apple was thinking. My guess is “Well, we only added those keys to keep that PC users happy. Let’s really mess with them. We don’t need to make them happy, we’ve got truckloads of brain-washed fanboy to keep up our User satisfaction numbers up”.

    Rob – June 6th, 2020
  27. Avatar for Sergio Schuler

    Works perfectly on Catalina - used Command instead of Ctrl though. SAVED MY PRODUCTIVITY. Oh my, thanks!

    Sergio Schuler June 8th, 2020
  28. Avatar for Dylan

    I don’t think this is working on Catalina.

    Dylan – June 8th, 2020
  29. Avatar for infoman

    Thank you!!! This worked like a charm on 10.15.5. “touch” command didn’t open notepad for me. I instead used finder to navigate to the file and drag it to notepad manually.

    infoman – June 8th, 2020
  30. Avatar for Magician

    Thank you for this, it worked great

    Magician June 14th, 2020
  31. Avatar for Vaibhav

    Awesone..! It saved my time and that was so frustating to work with documents. Thanks.

    Vaibhav – June 17th, 2020
  32. Avatar for martin

    Thank you, on Catalina with Logitech K850 works fine with text editors, but Safari intercepts home/end keys to go begin/end of page, no matter if cursor is inside of a text box.

    martin – June 23rd, 2020
  33. Avatar for Amy

    Thank you so much for this!! As someone brand new to Terminal, I had difficulty following only the instructions on this page to get things working. In case this helps anyone else, here’s a step-by-step of how I did it in Catalina:

    1) Open TextEdit, paste in the contents as given by Damien, and “Save As” DefaultKeyBinding.dict to your Documents folder. 2) Open Terminal (found in Applications/Utilities/) 3) Type in the following command and hit enter. (This will move the file you created to the desired directory): ~mv /Documents/DefaultKeyBinding.dict ~/Library/KeyBindings/DefaultKeyBinding.dict 4) Restart your computer.

    Amy – July 10th, 2020
  34. Avatar for Lance

    For those having trouble, make sure you created an actual .dict file, as opposed to a .txt file. To verify this: Right Click the file > Get Info. Expand Name & Extension to remove the ‘.txt’ if it is present and save.

    I also had to use “BeginningOfLine” instead of “BeginningOfParagraph” as user Brian mentions above.

    Lance – July 14th, 2020
  35. Avatar for Lolo

    Either I’m dull or struggling to get this to work!

    Here’s my code; a mix of Damien’s, Brian’s and suggestions from Sergio and Lance. Running Catalina 10.15.5:

    { “\UF729” = moveToBeginningOfLine:; // home “\UF72B” = moveToEndOfLine:; // end “$\UF729” = moveToBeginningOfLineAndModifySelection:; // shift-home “$\UF72B” = moveToEndOfLineAndModifySelection:; // shift-end “^\UF729” = moveToBeginningOfDocument:; // command-home “^\UF72B” = moveToEndOfDocument:; // command-end “^$\UF729” = moveToBeginningOfDocumentAndModifySelection:; // command-shift-home “^$\UF72B” = moveToEndOfDocumentAndModifySelection:; // command-shift-end }

    Then after making sure it’s a .dict file, adding to KeyBindings, and then killall Finder in terminal, still no dice. What could I be doing wrong here?

    Lolo July 21st, 2020
  36. Avatar for Lance

    @Lolo

    Try this: make sure your text in the .dict file is plain text and not rich text. To do this, go to Format > Make Plain Text and Save. Then killAll Finder and try again.

    Lance – August 2nd, 2020
  37. Avatar for Kevin

    @Lolo If you copied and pasted code from others on this webpage, your double-quote character could be wrong. Replace everything that looks like a double-quote with an actual double-quote. This has caused me problems many times when writing code.

    Also, your command-* key mappings are really ctrl-* mappings because you are using the ‘^’ character at the beginning of the sequence. If you really want to use the command key, substitute the ‘^’ character with a ‘@’ character.

    Kevin – August 4th, 2020
  38. Avatar for emmap

    Now it works on Catalina 10.15.6:

    1- given ownership to the user MyUser to the folder /Users/MyUser/Library/KeyBindings/ and to the file DefaultKeyBinding.dict chown MyUser /Users/MyUser/Library/KeyBindings/ chown MyUser /Users/MyUser/Library/KeyBindings/DefaultKeyBinding.dict

    2- given to all users all rights to the folder /Users/MyUser/Library/KeyBindings/ and to the file DefaultKeyBinding.dict chmod 777 /Users/MyUser/Library/KeyBindings/ chmod 777 /Users/MyUser/Library/KeyBindings/DefaultKeyBinding.dict

    3- then saved the file into ASCII format with CRLF line endings instead of LF.

    emmap August 9th, 2020
  39. Avatar for MrVestek

    This also works well on Catalina, however I find that the page will still scroll up / down when these keys are pressed, even though the behaviour is now as expected.

    Anybody know of a way to prevent this?

    Thanks so much!

    MrVestek – August 28th, 2020
  40. Avatar for Foil

    Can I get additional clarification with how to get it working on Catalina 10.15.6? I don’t really understand the instructions that @emmap has posted above. For steps 1 & 2, my user already has read and write access to the file and folder, and for step 3, I’m not really sure what any of it means.

    Foil – August 29th, 2020
  41. Avatar for Rich

    After trying to follow everything on here to no success, I found a website that had easy to follow instructions. Most importantly, my home and end keys work as I desire.


    https://www.iexplain.org/remap-home-and-end-buttons-for-external-keyboard-on-mac/

    Fire up your favorite terminal (you’re probably using iTerm2 like the rest of the world)

    mkdir -p ~/Library/KeyBindings nano ~/Library/KeyBindings/DefaultKeyBinding.dict

    The seasoned programmer could just go vi ~/Library/KeyBindings/DefaultKeyBinding.dict or more likely vim, but for the rest of us, nano works like a regular text editor.

    In the empty file you just opened, copy and paste the following:

    { /* 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:";  }
    

    Having pasted it into the file, press ctrl + x and answer with y when you get the question if you want to save.

    Well that’s it. Now you have successfully remapped the home and en button for macOS. You need to restart to make the changes happen. ***************************

    Rich – September 4th, 2020