This is the old (static) wiki. Please go here instead |
In OS X, various keystrokes move the cursor around in exactly the same way as they do in the text editor emacs. For example, in both emacs and TextEdit.app, C-f (control-f) moves the cursor forward one character. (Many emacs-like keybindings are set up by default; you can get access to a few more by copying this DefaultKeyBinding.dict in ~/Library/KeyBindings.)
Unfortunately, some key combinations—though they work in other Cocoa apps—do not work in TextMate. (This is mostly because TextMate binds other commands to the relevant key combinations.) This page: (1) explains how to get TextMate to behave more like emacs; and (2) records the emacs commands that are not supported by TextMate (focusing on those commands that are available to other Cocoa apps).
How emacs behaves : this is what we’re aiming for. (This appear to be a link to an illegal copy of some O’Reilly material; a link to something similar, but legal, would be better!)
Emacs-like commands that are bindable in other Cocoa apps (tested: Mail.app, TextEdit.app, SubEthaEdit.app), but not TextMate:
setMark (C-@, C-SPACE)
deleteToMark (C-w)
yank (C-y)
moveForward1 (C-f)
deleteForward2 (C-d)
(Names taken from Apple’s NSResponder documentation.)
1 In TextMate, C-f is bound to reformatText; if you bind this to something else (e.g. M-q, emacs’ default—do this by editing /Applications/TextMate.app/Contents/Resources/KeyBindings.dict), C-f will revert to being moveForward.
2 In TextMate, C-d duplicates the current line. This is a preset macro “Duplicate Line”—edit the macro to erase (or reassign) this binding (via Automation | Replay Macros | Edit Macros…), and C-d will revert to delete forward.
Emacs-like commands that don’t work quite right in TextMate:
deleteToEndOfLine (C-k)—this doesn’t delete the line if the line happens to be empty.
Emacs-like commands that are unavailable in OS X, but nice to have in TextMate:
isearch-forward (C-s)—incremental search
isearch-backward (C-r)—incremental search
spell-word (M-$)—checks spelling of word under cursor
split-window-horizontally (C-x 2)—(or some other way to get two views of the same file)
delete-other-windows (C-x 1)
backward-paragraph (M-[)
forward-paragraph (M-])
switch-to-buffer (C-x b)—Default switches to last open buffer (see request for history list)
advertised-undo (C-x u or C-)—this is basically just the regular undo, but I don’t see how to bind this to C- in Cocoa; there doesn’t seem to be an “undo” command.
(Names are emacs commands .)