They didn’t put the Mac in Emacs for nothing. (Dear Usual Pedants: I am aware that Emacs predates the Mac. This is an attempt at wit. A bad one, I’ll give you.) Did you know that you could use Emacs navigation keys in TextEdit? And Terminal? And many other Cocoa apps? They all work the way you’d expect. Well, at least mostly. In TextEdit, ^N and ^P go to the beginning and end of word-wrapped paragraphs, not just lines.

  • ^B: Move cursor back one character
  • ^F: Move cursor forward one character
  • ^P: Move cursor up one line to previous line
  • ^N: Move cursor down one line to next line
  • ^A: Move cursor to start of line/paragraph
  • ^E: Move cursor to end of line/paragraph
  • ^D: Kill character to the right of the cursor
  • ^H: Kill character to the left of the cursor
  • ^T: Transpose the characters to the left and right of the cursor
  • ^K: Kill all text to the end of the paragraph
  • ^Y: Yank back all text from the kill buffer
  • ^V: Scroll down one page
  • ^O: Insert a line break without moving the cursor

(There’s also ^L to center your selection, but I haven’t seen it used in many Cocoa apps.)

Your keybindings are defined in /System/Library/Frameworks/AppKit.framework/Resources/StandardKeyBinding.dict. This Apple document shows how to expand the emacs key-bindings further.

In Terminal, use the Emacs key-bindings to scroll back and forth through your command history (^P, ^N) and to edit the contents of the current command line (^B, ^F, ^H, ^D, ^A, ^E, ^T, etc). Add ^U to the mix to clear the command-line completely.

Don’t overlook the elegant double-escape completion feature that works so well with the other editing commands. For example, type % cd ~/De and then type ESC-ESC to automatically complete “Desktop”.

While I’m speaking about Terminal, don’t forget that you can always drop a file icon onto the command line to see its path. That includes the little icon found in the title bar of most documents, such as the ones in TextEdit. Save your text file and then move the cursor over the little icon in the title bar. Press the (left) mouse button, Wait for the icon to turn dark and then drag it out of the title bar and drop it onto the command line or into any other program for that matter. (Again, this won’t work unless the document has been saved. The “saved” title bar icon is dark. The “modified” icon is slightly lighter in hue.)

Finally, for extra Terminal-fu, you may want to bone up on the “bang” commands that work in nearly all the shells provided in OS X (/bin/*sh*). !! means repeat the previous command. !-2 means repeat the command just before the previous one (aka “go back 2 items in the history list”), and !5 means do command 5 in the history list. A bang followed by a few letters searches for the previous command that started with those letters, e.g. !cc reruns the last cc command issued.

I think I’ll stop now.