To answer the one about how to get the beginning or end of the line, it appears that by default Terminal maps these keys to it:
- shift+home → beginning of line, equivalent to the "home" key in normal terminals
- shift+end → end of line, equivalent to the "end" key in normal terminals
If you want home and end to work the "normal" way (and not require shift), go to [Terminal menu] → Preferences → Profiles tab (or settings on some versions of OS X) → Keyboard sub-tab.
Then modify/add these keys to be the following "send string to shell"
You can get the
\033 part by hitting the escape key within the edit dialog input, if you need to add it.
Then home and end will work like normal again (phew).
Also note that "alt + ←" and "alt + →" by default in terminal map to word left and word right, another handy combo to remember.
In later versions of Mac OS X, if the terminal screen shifts up or down when you press the home/end key, the home key may need to be set to
\033[1~ and the end key to
\033[4~ to get the results you want (no shift needed).
The above instructions work only for bash shell. However, for MacOS Catalina (v10.15) and later versions (BigSur and Monterey), the default terminal shell is zsh. So the following command is needed to map home/end keys, using bindkey widgets:
sudo echo 'bindkey "\033[H" beginning-of-line; bindkey "\033[F" end-of-line' >> ~/.zshrc
Feel free to modify this answer to add more useful key bindings, as it is a community wiki.