Fixing Home, End, Page Up, and Page Down in Leopard’s Terminal

Well, if you’re like me, you used to be pro-Windows. Then you found and fell in love with Linux. Then you realized how complicated it was to emulate your Windows software in a Linux environment, or get the Broadcom wireless card on your Dell laptop to work.

Then you discovered the Mac. Sleek. Sexy. Expensive… and the best of both worlds. A Unix-based platform, native Adobe apps, [paid] support, and a real terminal!

But wait, trouble in paradise — our favorite Windows/Linux key commands (Home, End, Page Up, Page Down) aren’t working as inspected. In fact they’re different throughout the OS.

Well, kids, after researching, I’ve finally got a working solution for Terminal.app:

  1. Open Terminal.app
  2. Open the Preferences window (CMD+,)
  3. Click the Settings tab
  4. Select your current Settings theme, and click on the Keyboard tab
  5. Edit (or Add) the entry for Home
    • Set Action: to send string to shell:
    • Set the string to \001 (or press Ctrl+a)
  6. Edit (or Add) the entry for End
    • Set Action: to send string to shell:
    • Set the string to \005 (or press Ctrl+e)
  7. Edit (or Add) the entry for Page Up
    • Set Action: to send string to shell:
    • Set the string to \033[5~ (copy and paste this in)
  8. Edit (or Add) the entry for Page Down
    • Set Action: to send string to shell:
    • Set the string to \033[6~ (copy and paste this in)
  9. Close the settings window.

There you go. Terminal should be ready to use the Home, End, Page Up, and Page Down keys as expected by Windows/Linux users.

SSH into your favorite Linux server, open nano, vi, or emacs and enjoy.

These articles made this article possible:

39 Comments

  1. Breakpoint says…

    Close, but no cigar on the Home and End keys, at least for vim. Try these instead:

    Home: 33[7~
    End: 33[4~

    Enjoy!

  2. Breakpoint says…

    Damn, the comment processor was not written with proper techs in mind! Make those as they are in the article:

    Home:
    backslash zero three three left-square-bracket seven tilde

    End:
    backslash zero three three left-square-bracket four tilde

    …hopefully that also clarifies things for those of you having unicode issues with the preceding. =]

  3. andy says…

    @breakpoint thanks, mine works great for basic terminal work as well as nano. Haven’t tried vim though.

    Thanks for the additional info, not sure why WP killed your slash. Probably something to do with it’s slash escaping through GET/POST requests.

  4. koz says…

    saved me allot of frustration on my MBP!

    except i set ctrl+up to page up etc etc

    you rock!

  5. meeba says…

    Woo!! Breakpoint in the house!!!!! Almost every site out there has the quick fix with ctrl+a and ctrl+e but does NOT work in vi. I copy/pasted your home and end codes and they worked great in vi both in normal mode and insert mode. Rock! Thank you!

  6. meeba says…

    oops just noticed that unfortunately the vi fix doesn’t work with home/end in Terminal. it just prints out a “~” doh!

  7. Doc says…

    Yeah, these mappings are good for use in VI and some other command line apps, but indeed, it doesn’t actually work (home/end) in the terminal itself. I seriously can’t stand how this is even a problem. Ugh, Apple, you do so well in general, but this is actually a point of real frustration for me!

  8. Olof says…

    Great tip, this one actually works in VI!!!

  9. MB says…

    this is driving me mad…

  10. Ted R. says…

    I hate Macs. The most counter intutitve devices ever made.

  11. andy says…

    @Ted, easily a million people out there to discount that statement without clarification/details ;p

  12. nikhil says…

    Awesome! thanks! this saved me a lot of time and frustration.

  13. Matthew Miller says…

    Andy, thanks! After trying several sites with 33[4~ and other variants, including .initrc mods, your simple change made home/end finally work in Bash and Nano! Wohoo!

    (PS: Ted, troll elsewhere.)

  14. Costyn says…

    Thanks Breakpoint, your octal digits work perfectly in VI

  15. shams says…

    thank you thank you thank you. both of you.

  16. Jordan says…

    THANK YOU SO MUCH!!
    I’ve been frustrated with this for a long time. Now there’s beauty in the world again 😉

  17. Nick says…

    Home: 33[7~
    End: 33[8~

    xterm-color
    UTF-8

    Works for me on the command line, in vi, vim, and nano.
    Cheers

  18. Nick says…

    May have to restart the terminal for changes to take effect.

  19. Nick says…

    And add these lines to ~/.inputrc

    “\e[7~”: beginning-of-line
    “\e[8~”: end-of-line

  20. HPLogsdon» Blog Archive » Terminal.app Home and End keys and Vim says…

    […] This post on theandystratton.com from back in 2009 is one I’ve had to go to a couple of times to remember exactly how to enter in the correct keycodes in Terminal.app’s preferences. His method just takes the wimple approach of aliasing the old terminal keycodes of CTRL+a and CTRL+e (home and end, respectively) into the home and end keys on the OS X keyboard. Unfortunately, those keycodes end up not working in VIM. […]

  21. Fix Home & End in Snow Leopard’s Terminal | Mike Roher says…

    […] Andy Stratton‘s post, I made two quick changes and boom! I had two working buttons which I’ve never […]

  22. Adam Chainz says…

    Thanks, that saved my bacon on home/end!

  23. Antti says…

    Thank you so much!

  24. Chris says…

    So I’m staring at my mac keyboard, and lo and behold – it has no HOME, no END, no PgUP and no PgDOWN keys…
    What’s the combo of keys we’re expected to push to get those on our keyboard??

  25. Chris says…

    If you’re adding these:-
    “\e[7~”: beginning-of-line
    “\e[8~”: end-of-line
    remember to erase the ” chars and manually re-type them on your keyboard… if you copy/paste from here, it stick in some unicode 66\e[7~99 stuff which you probably don’t want

  26. Fix home, end, pageup, pagedown keys in mac terminal vim - Dhruba Bandopadhyay says…

    […] [Credit] […]

  27. Narada says…

    Thank you so much for this post. Though I had to switch to Breakpoint’s strings for home and end to use vim!

  28. Andrew Coy says…

    was working on something in terminal (which is more new to me) and ended up on this page — was fun to look up at the url after a bit and realize this was your blog and that i knew you in real life. thanks for putting stuff like this out there.

  29. andy says…

    @Andrew thanks! When I have an issue that stresses me/takes me longer than a simple search to figure out, I typically post about it in hopes it takes someone else far less time to fix.

  30. Home and End Shortcuts in Terminal | Web App Log says…

    […] Fixing Home, End, Page Up, and Page Down in Leopard’s Terminal […]

  31. Commodore says…

    Easy fix for vim here, add the following to your ~/.vimrc:

    ” key remaps for OSX to make vim play nice with the external keyboard
    ” home/end remapped as ctrl+a/e respectively in terminal.app here
    map
    map

  32. Commodore says…

    bah, it ate some stuff. Let’s try again:

    map <C-A> <Home&rt;
    map <C-E> <End>

  33. Commodore says…

    > not &rt.

  34. Commodore says…

    and to make that work in input mode:

    imap <C-A> <C-O><Home>
    imap <C-E> <C-O><End>

  35. Jeff Mikels says…

    I found a better solution….

    Home should be “33OH” ( that’s zero three three “O” “H” )
    End should be “33OF” ( that’s zero three three “O” “F” )

    Works great in local vim, in ssh sessions, and when using gnu screen.

  36. jeff mikels » How to Fix “Home” and “End” keys in the Mac Terminal says…

    […] Fix the OS X Terminal […]

  37. Doc says…

    This didn’t exactly work out for me.. But I figured out what did (and the comments here got me close).

    I posted my solution here:
    http://apple.stackexchange.com/questions/26930/how-can-i-achieve-page-up-and-page-down-in-os-x/123160#123160

  38. ex-frustrated macvim user says…

    YES! This worked, thanks so much!

    PS – I went ahead and used Breakpoint’s modifiers for Home and End from the comments section.

  39. Ravi says…

    Awesome. Works like charm.

RSS feed for comments on this post. TrackBack URL

Leave a Comment

February 17, 2009

Filed in Uncategorized

There are 39 comments »


« Back to the Blog