Yes, I know these work in more than just OS X, but I wanted to focus on getting it configured correctly within xterm applications running on OS X.
This only works for Emacs Mode. Your shell might be in Vi mode, but you might already know this since it's not the default. The shell editing and command history sections also work when editing in an emacs editor.
- In Terminal.app, open preferences and go to the
Settings->Keyboard tab. Check the "Use option as meta key" check box.
- If you use iTerm, go into Manage Profiles, select the global or xterm keyboard profiles (whichever one your bookmark is using, or just do both) and set "Option Key as" to "+ESC".
Shell Editing:
- Ctrl + A: Move the cursor to the beginning of the line
- Ctrl + E: Move the cursor to the end of the line
- Ctrl + L: Clears the Screen, similar to the clear command
- Ctrl + H: Same as backspace
- Ctrl + W: Cut the word before the cursor
- Opt + D: Cut the word after the cursor
(don't confuse with Ctrl + D) - Ctrl + U: Cut everything before the cursor
- Ctrl + K: Cut everything after the cursor
- Ctrl + Y: Paste the last thing to be cut.
- Ctrl + T: Transpose the last two characters before the cursor
- Opt + T: Transpose the last two words before the cursor
- Opt + B: Move back one word
- Opt + F: Move forward one word
- Ctrl + _: Undo (also "Ctrl + -" works)
Command History:
- Ctrl + R: Let’s you search through previously used commands for lines matching a specified search string.
- Ctrl + G: While in search mode, aborts the current search and restores the original line.
- Ctrl + J: While in search mode, terminates a search and places the current item from the search on the line.
- <return>: While in search mode, terminates a search and places the current item from the search on the line and executes it.
For more advanced Readline Emacs Editing Mode shortcuts, you can get a copy of the Readline Emacs Editing Mode Cheat Sheet and work on making them function in your OS X xterms application. The shortcuts listed above are the most useful for me and I hope this helps you out.