Emacs Cheat Sheet
Starting
- emacs [file name]
- Ctrl-h t Tutorial
Quiting & Exiting
- C-x C-c
"Close". You will be prompted whether you wish to save any changes. Type 'n' for no. You'll be asked if you are sure and you'll need to type 'yes'
- C-g
- Stop a command that's not responding
- Clear a Prefix Argument
- C-_ Undo
Cursor Movement Commands
- C-f Move forward a character
- C-b Move backward a character
- M-f Move forward a word
- M-b Move backward a word
- C-n Move to next line
- C-p Move to previous line
- C-a Move to beginning of line
- C-e Move to end of line
- M-a Move back to beginning of sentence
- M-e Move forward to end of sentence
Screen Movement Commands
- C-v Scroll down one screen
- M-v Scroll up one screen
- C-l (that's L not 1) Center cursor on screen
- M-< Scroll to the begining of the file
- M-> Scroll to the end of the file
Prefix Argument
- C-u
Example: C-u 23 C-f will move the cursor ahead 23 characters
-
Most commands use the numeric argument as a repeat count, but some commands use it in some other way. Several commands use it as a flag--the presence of a prefix argument, regardless of its value, makes the command do something different.
C-v and M-v are another kind of exception. When given an argument, they scroll the screen up or down by that many lines, rather than by a screenful. For example, C-u 8 C-v scrolls the screen by 8 lines.
Help
- C-h Help
- C-h t eMacs Tutorial
- C-h k [key combination to you want to find out about] Keystroke description
- C-h f [built in function name] Describe built-in function.
e.g. C-h f query-replace-regexp
Search & Replace
- C-s SearchString Enter Simple Incremental Search
- ESC % Query-replace
- Prompt changes to Query replace: Type literal search string e.g. 'foo'. Type Enter.
- Prompt changes to Query replace foo with: Type literal replacement string e.g. 'bar' Type Enter.
- Prompt changes to Query replacing foo with bar: (? for help)
- Type ! to replace all
- y to replace just that instance
- n to move to next without replacing.
- ? for help
- M-x query-replace-regexp Enter
- M-x que
- tab completion until you have M-x query-replace-regexp
- Enter
- Prompt changes to Query replace regexp: Type regex. e.g. Query replace regexp: <img\([^>]+\)>. eMacs requires escaping parentheses. Hit Return
- Prompt changes to Query replace regexp: <img\([^>]+\)> with: Type regex replace e.g. Query replace regexp: <img\([^>]+\)> with:\1
- Enter for interactive search and replace.
Cut & Paste
(Kill & Yank)
- M-w Copy
- C-w Kill (analogous to 'cut')
- C-y Yank (analogous to 'paste')
- Mark begining of 'selection' with C-@, then move cursor to end of 'selection' and type C-w
- The clipboard is refered to as the Kill Ring
Windows
- C-x 1 Close all but '1' window
- C-x o Move to 'other' window. Cycles through all windows.
BBEdit
Emacs Local Variables
Emacs (the popular Unix text editor) supports a convention in which you can define Emacs-specific settings in a block of text near the end of the file, or in the first line of the file. BBEdit now recognizes the Emacs variable block, and can optionally read and set certain variables. If this option is selected, BBEdit will use the "coding" variable, whose value is the Internet text encoding name in which the file is written, e.g. "iso-8859-1" or "utf-8" to interpret the file's contents when opening it.
Emacs Key Bindings
The Text Editing panel of the Preferences window contains a checkbox labeled Use Emacs Key Bindings. When this option is turned on, BBEdit will enable the following Emacs-style keyboard navigation commands. The Escape key is specified in lieu of the Emacs "Meta" key; to use these key equivalents, press and release the Escape key followed by the specified letter key--for example, to type "Esc-V" press and release the Escape key and then type the letter V.
Key Sequence Action
- Ctl-A beginning-of-line (Move insertion point to start of current line)
- Ctl-B backward-char (Move insertion point backward 1 place)
- Ctl-D delete-char (Delete forward 1 character)
- Ctl-E end-of-line (Move insertion point to end of current line)
- Ctl-F forward-char (Move insertion point forward 1 place)
- Ctl-G keyboard-quit (cancel pending arguments)
- Ctl-K kill-line (Delete to end of current line)
- Ctl-L recenter (Scrolls the current view so the selection is centered on screen)
- Ctl-N next-line (Move insertion point down one line)
- Ctl-O open-line (Inserts line break without moving insertion point)
- Ctl-P previous-line (Move insertion point up one line)
- Ctl-R isearch-backward (Quick Search with the Backwards option)
- Ctl-S isearch-forward (Quick Search)
- Ctl-T transpose-chars (Exchange Characters)
- Ctl-U universal-argument (See note below)
- Ctl-V scroll-up (Page down)
- Ctl-W kill-region (Cut)
- Ctl-Y yank (Paste)
- Ctl-_ undo (Undo)
- Ctl-X Ctl-C save-buffers-kill-emacs (Quit)
- Ctl-X Ctl-F find-file (Open file)
- Ctl-X Ctl-S save-buffer (Save current document)
- Ctl-X Ctl-W write-file (Save As)
- Esc-< beginning-of-buffer (Move insertion point to start of document)
- Esc-> end-of-buffer (Move insertion point to end of document)
- Esc-Q fill-paragraph (Hard Wrap with current settings)
- Esc-V scroll-down (Page up)
- Esc-W copy-region-as-kill (Copy)
- Esc-Y yank-pop (Paste Previous Clipboard)