The Mac Terminal.app is one of the best Terminals I have used, but it has some annoying quirks like not supporting standard key definitions out of the box. The most frustrating ones are Home and End.
In nearly every OS, Home has meant “go to the beginning of the line” and End has meant “go to the end of the line,” but on the Mac, the default has always been for Home to scroll a document up to the top and for End to scroll the document down to the bottom.
However, since most Terminal applications aim for the Unixy world, they don’t care about scrolling through documents as much as dealing with the line you are on.
Luckily, the Mac Terminal has the ability to let the intrepid user customize it’s keybindings. If you want to make your Terminal operate like a standard Unix-like terminal, follow these simple steps:
- Open the Terminal app.
- Select Preferences from the Terminal Menu.
- Under Settings, select a Profile you want to change.
- In the right pane, select the Keyboard button to see keyboard settings.
- Select the line that has the word “home” in the “Key” column.
- Click the Edit Button at the bottom.
- Make it look like this:
- To enter the right key code, clear the box and type these keys in order: ESCAPE O H (that’s a capital letter o, not a zero)
- The right key code for “end” is exactly like “home” but you replace the “H” with an “F”.
Some Linux/Unix Friendly Keycodes (submit your own in the comments):
- home ::
\033OH
- end ::
\033OF
- F1 ::
\033[11~
- F2 ::
\033[12~
- F3 ::
\033[13~
- F4 ::
\033[14~
Other links that worked but had problems:
The main problem with each solution below is that they only work part of the time. My solution above is compatible with the latest version of Mac OS X (Mountain Lion), and is also the default key binding for xterm, remote shells (ssh), vi(m), and also GNU screen. Each of the solutions below only work in a few of the cases for me.
vitb
Hey man, it worked 🙂 Thanks a lot for recipe than works even for Vim in Terminal.app. Great!
JThott
Hey,
Thanks a lot. It worked like a charm!
Kanishka Dutta
Thank you for sharing this.
Works for me.
dood
this doesn’t work in mojave. there is no longer a ‘send string to shell’ option for the action.
Scott
Just use the send text option and it works fine, confirmed in Catalina as well.
mai ling
can you make home and end macos-wide function sanely like on linux and windows?
Ahti
Thanks a lot Jeff! Works like a charm on Big Sur.
Utsav
This worked!
Jason
Thank you for this, I know its old but it worked like a charm.
Steve
For anyone using the vi key bindings (bindkey -v) in their shell, change the mappings to Home (0) and End ($). That is a zero, not a letter O.
Steve
My previous comment didn’t escape my angle brackets correctly. That should be Escape+0 and Escape+$.