Terminology
-----------

S = Shift
C = Ctrl
M = Meta/Alt/Option/whatever
M1/M2/M3 = Mouse buttons (left, middle, right)

Basics
------

C-x C-c              Exit emacs
C-x s                Save all edited files, prompting for each one
ESC ESC ESC          Escape from stuff (cancel a prompt, get rid of 
                     extra windows like C-x 1 described below, get out
                     of recursive editing mode, etc.)  Hit ESC 3 times.
C-g                  Cancel a prompt or a long-running Emacs operation

Left/Right/Up/Down   Move normally in file
C-Right/Left         Next/Prev word
Home/End             Beginning/End of line
C-Home/End           Beginning/End of file
Insert               Toggle insert mode
Delete/Backspace     Delete next/prev char
C-Delete/Backspace   Delete next/prev word
C-s                  Incremental search
C-r                  Incremental search reverse

CUA mode
--------

- Windows "Common User Access" mode (standard Windows editing keys)
- Available (on all versions of Emacs including Aquamacs)
  via any of:
  - Options menu
  - M-x cua-mode
  - .emacs init file:  (custom-set-variables  '(cua-mode t nil (cua-base)))
- CUA Mode keys:
  S-Arrow            Select
  S-Delete           Cut
  S-Insert           Paste
  S-Home/End         Select to beginning/end of line
  C-S-Home/End       Select to beginning/end of file
  C-c                Copy (if anything selected, otherwise non-CUA C-c)
  C-v                Paste
  C-x                Cut (if anything selected, otherwise non-CUA C-x)
  C-z                Undo
  C-Enter            Toggle rectangular region mode
                     - Enter    Cycle through corners of rectangle
                     - Arrow    Extend region by moving active corner
                     - Click    Re-start specifying rectangle
                     - Char     Insert a regular char into each line just 
                                outside the rectangle on the side 
                                specified by the active corner
                                - Good for indenting
                                - Good for creating vertical lines
                     - Delete   Delete rectangle, shifting other text left
                                - Good for un-indenting
                     - S-Delete Cut rectangle, shifting other text left
                     - C-x      Cut rectangle, shifting other text left
                     - M-k      Cut to be inserted as lines, not rectangle
                     - C-c      Copy rectangle
                     - M-m      Copy to be inserted as lines, not rectangle
                     - S-Insert Paste previously cut or copied rectangle,
                                shifting other text right
                     - C-v      Paste previously cut or copied rectangle, 
                                shifting other text right                 
                     - M-r      Replace first occurrence of regexp on each 
                                line within the rectangle      
                     - M-a      Delete leading spaces at left edge of 
                                rectangle, shifting all text of lines 
                                left.
                                - Good for left-aligning columns of text
                     - M-o      Insert rectangle width of blanks, shifting
                                current rectangle contents right
                     - M-c      Delete leading whitespace within rectangle
                     - M-b      Replace rectangle contents w/blank spaces
                     - M-s      Replace rectangle contents w/specified string
                     - M-f      Fill rectangle w/specified char
                     - M-n      Replace rectangle contents w/sequential numbers
                     - M-i      Increment all numeric values in rectangle
                     - M-p      Treat region as a true rectangle by padding
                                any short lines w/trailing blank spaces, so
                                the above actions operate on the same number
                                of chars for short lines as for longer lines 
                                (useful for M-f especially)
                     - M-P      Insert whitespace to make region a rectangle
                     - C-M-Up/Down Scroll text up/down within the rectangle
                     - M-q      Wrap text within rectangle (see M-q below)
                     - M-R      Reverse order of lines within rectangle
                     - M-t      Replace entire rectangle contents with a
                                text string
                     - M-|      Pipe rectangle contents through shell command
                     - M-'      Restrict rectangle operations to apply only
                                to lines of rectangle that start with a 
                                specified char
                     - M-/      Restrict rectangle operations to apply only
                                to lines of rectangle that start with a 
                                specified regexp

  C-S-Space          Toggle global mark mode
                     - When a global mark is set at a location in a buffer,
                       any text typed is inserted there, and any text cut,
                       copied or deleted is inserted there, so you can move
                       around to various buffers, in various windows, etc, 
                       copying text, entering new lines or commas, and such, 
                       and it's all being inserted at the global mark in one 
                       of your buffers.  Keep the global mark visible in a
                       window if you want to see it as it happens.
  M-v                Repeat previous replace that happened by selecting a
                     string and overtyping it.
  C-x C-z            Minimize the editor window
- Prefix any copy, cut or paste command, regular or rectangular, with C-digit 
  to operate on the register (numbered paste buffer) specified by the digit.
- Use regular non-CUA C-x and C-c keys via either holding Shift key as:
      S-C-x
      S-C-c
  or repeating Ctrl key as:
      C-x C-x 
      C-c C-c
- For more details of CUA mode, read the comments at the top of:
      <emacs-install-directory>\lisp\emulation\cua-base.el

In Both CUA and non-CUA Modes
-----------------------------

C-/                  Undo
C-x u                Undo
C-_                  Undo
C-f                  Or any harmless command to end a sequence of undos, pushes
                     the recent sequence of undos onto the undo stack, so that 
                     subsequent undos undo the undos, redoing the changes.
C-u C-/              Undo changes within the selected region only
                     - In transient-mark-mode, C-/ does it automatically w/o C-u

C-h c                Show a brief description of specified key binding
C-h k                Show a longer description of specified key binding
C-h K                Show a even longer description of specified key binding
C-h b                Show all key bindings
C-h m                Show active major and minor modes
C-h v                Show value and docs for specified Emacs variable
C-h a regexp         Search all one-line command descriptions for regexp
C-h d regexp         Search entire docs of all commands for regexp

C-f/b                Next/Prev char
C-n/p                Next/Prev line

C-a/e                Beginning/End of line
M-f/b                Next/Prev word
M-a/e                Next/Prev sentence
M-v/C-v              Next/Prev screen
M-</>                Beginning/end of buffer
M-g g                Goto line number

C-l                  Scroll current line to 3 locations
                     - Center of window
                     - Near top of window (5th line)
                     - Near bottom of window (6th from bottom)

C-M-f/b              Forward/back to matching quote, brace, paren, or 
                     square bracket (cursor must be before open or after
                     close)

Drag mouse           Select a region
C-Space              Set mark (then move cursor to select region -- the 
                     region between the set "mark" and the current "point")
C-w                  Cut (kill)
                     - Use this to cut in rectangular mode if you later want
                       to paste as full lines, but may have to paste
                       via C-y, not Cmd-V in Aquamacs
M-w                  Copy
C-y                  Paste (yank)

C-x h                Select all
M-h                  Select paragraph

C-x C-x              Set new mark and return to previous mark (toggle)
                     (Easy way to set a bookmark, then go elsewhere, then 
                     toggle back and forth between locations.)
  When you...                                   Mark is set to...
  Jump to either end of the buffer (M-< or M->) your previous location
  Exit incremental search                       where you began searching
  Yank text                                     beginning of yanked region
  Insert a buffer or file                       beginning of the inserted text
C-u C-Space          Cycle through 16 recent marks
C-x n n              Narrow future operations to apply only to selected region
C-x n w              Widen future operations to apply to entire file
M-d                  Cut word
C-k                  Cut to end of line
M-k                  Cut to end of sentence
M-y                  Cycle through pastes of recent cuts and copies

C-s/r                Incremental search forward/reverse
                     - C-s/r again      next/prev
                     - Enter            end search, going to match
                       - C-x C-x        return to start location
                     - C-g              cancel search (return to start location)
                     - M-c              toggle case-sensitivity
                     - M-r              toggle regular-expression mode.
                     - M-n/p            next/prev string in search history
                     - M-e              edit the search string

C-s C-s              Search again
C-s C-w C-w C-w ...  Incremental search for word(s) at cursor
C-h C-s              More incremental search options

M-%                  Replace
                     y/Space    Replace
                     n/Delete   Skip
                     q/Enter    Exit
                     .          Replace once and exit
                     ,          Replace w/o next search
                     !          Replace all
                     ^          Back to previous match
                     E          Edit replacement string
                     C-r        Enter recursive edit (C-M-c to exit)
                     C-w        Delete match and recursive edit
                     C-l        Refresh screen and center current line
                     ?          Help

C-M-s/r              Incremental regexp search forward/reverse
                     - C-M-s/r again      next/prev
                     - Regexp chars:  . *+? ^$ [] [^] \( \) \|
M-x re-builder       Regexp builder and tester
M-x occur            Find all regexp (show list of all matches in file)
C-M-%                Regexp Replace
                     \&                 original found text
                     \1, \2, etc.       parenthesized subgroups in found text
                     \#                 number of replacements done so far
                     \?                 prompt user for string on each match
                     \,(lisp-expression...)  Any Lisp expression

C-s/r Enter          Non-incremental search

C-u nnn              Repeat count (nnn) for next keystroke (default 4)
M-digit M-digit ...  Enter digits of repeat count for next keystroke

C-x 1                Single window
C-x 2                Split current window top/bottom
                     - Can then drag divider w/mouse 
                     - C-x +    Balance window sizes
                     - C-x ^    Grow window taller
C-x 3                Split current window left/right
                     - Can not drag divider w/mouse
                     - C-x }    Grow window wider
C-x 0                Delete current window reclaiming space
M3 on statusbar      Delete current window reclaiming space
C-x o                Goto next window

C-x 5 2              Open new "frame"
                     This is a new OS window which can be separately resized,
                     minimized, etc., can overlap other windows, and starts 
                     with the same contents as the current window of the 
                     current frame, keeping them synchronized as you type.
C-x 5 0              Close frame

C-x Right/Left       Next/Prev buffer
                     - Or M1/M3 on buffer name
C-x k                Close buffer, confirming if changed
                     - Or toolbar button
C-x C-b              List of buffers
C-x b                Goto buffer by name (TAB to autocomplete)

C-x C-f              Open file
C-x i                Insert contents of file into this buffer
C-x C-s              Save current file
C-x s                Save all edited files, prompting for each one
C-x C-r              Open list of recently edited files
C-x d                Open directory in directory editor, where you can
                     navigate to and manipulate files.
Speedbar             You can open the "speedbar" via the menu:
                         Options | Show/Hide | Speedbar
                     Then right click on the new window it creates and 
                     choose Speedbar | Displays to set it to show the 
                     names of files on disk or buffers in the editor.
                     Then use it to navigate to and manipulate files or
                     buffers.

C-x r m              Set bookmark
C-x r b              Goto bookmark
C-x r l              Edit bookmark list

C-x r Space          Store current position in a register w/a one-letter name
C-x r j              Goto position stored in named register
C-x r s              Copy selected region to named register
C-x r i              Insert text from named register

C-x r k              Rectangular cut
C-x r y              Rectangular paste
C-x r o              Insert rectangle of white space, pushing text right
                     - Good for indenting code
C-x r c              Clear rectangle, replacing contents w/spaces

C-x r r              Rectangular copy to register
C-x r i              Rectangular paste from register, leaving cursor unmoved
                     - Good for pasting rectangles copied via C-x r r to
                       indent or otherwise prefix a set of lines multiple
                       times.

C-q                  Insert special char, like Ctrl-L, into buffer or search
C-x =                Show current position and current char's encoding

M-u                  Uppercase word or CUA-mode rectangle
M-l                  Lowercase word or CUA-mode rectangle
M-c                  Capitalize word

C-x .                Set fill prefix to chars preceding cursor on this line
                     - C-x . in first column to clear fill prefix
M-q                  Fill paragraph using fill prefix 
                     - Useful to word-wrap a comment preserving comment
                       delimiters like // on each line
                     - Always wraps to column 70.  How to set right margin?
                       C-u number C-x f  does not work.  Bug?
                     - A paragraph is a set of consecutive lines that 
                       already start with the fill prefix
                     - Can also fill within a CUA-mode selected rectangle.

C-M-\                Indent selected text, following usual indent rules, 
                     or prefix it with fill prefix , if any
C-x Tab              Indent selected text rigidly.
C-u nnn C-x $        Hide lines indented nnn or more spaces
C-x $                Show all hidden lines
M-x set-selective-display Show all hidden lines

C-x C-q              Toggle readonly flag

M1 on --\--          3rd hyphen     Toggle readonly flag
                     4th hyphen     Toggle modified flag

F3                   Start recording macro
C-x (                Start recording macro
F4                   Stop recording macro
C-x )                Stop recording macro
F4                   Play back macro once
C-x e                Play back macro once
M-digit F4           Play back macro digit times
M-0 F4               Play back macro over and over until it fails

M-x ?                Show list of all emacs functions
M-x                  Execute an emacs command
M-:                  Execute a Lisp command, like:  (info "(emacs)Using Region")
M-x shell            Run an interactive command shell
M-!                  Run a single shell command
M-|                  Pipe selected text into a shell command
                     - Can also pipe text of CUA-mode selected rectangle.
M-x untabify         De-tab the selected region (convert tabs to blank spaces)
M-x auto fill mode   Toggle mode of words wrapping to new lines as you type
                     - C-u number C-x f   Set margin for wrapping (default 70)
                     - M-q                Re-fill after editing an existing line
M-x dired            Directory editor (same as C-x d)
                     Click filenames or Enter to edit files
                     C-x C-q to edit filenames, etc. (doesn't work?)
                     C-x C-s to save edits to filenames
M-x compile          Run make w/specified args, capturing output in new buffer
M-x gdb              Run GDB (GNU debugger)
M-x grep             Grep files, showing matches in new buffer
M-x man              Man pages
M-x calculator       Calculator
M-x calendar         Calendar

M-x java-mode        Mode for editing Java files
M-x python-mode      Mode for editing Python files
M-x text-mode        Mode for editing text files
M-x fundamental-mode Mode with no specializations at all

M-x auto-fill-mode   Wrap typed text at auto-fill chars (default:70)
M-x flyspell-mode    Spell checker as you type
M-x follow-mode      Wrap single buffer into multiple side-by-side windows

M-x find-file
M-x eval-expression

C-x >                Scroll right
C-x <                Scroll left

F1                   Same as C-h in all cases
C-h ?                Options of help commands
C-h f                Show all emacs commands (all valid args to M-x)
C-h F                Show manual section for emacs command
C-h w                Show keys (if any) bound to emacs command
C-x C-h              Show all key bindings starting with C-x
C-h C-h              Show all help features
C-h r h              Tutorial on Info reader (the help system)
C-h t                Emacs tutorial
C-h r                Emacs manual
                     Also at:
                          http://www.gnu.org/software/emacs/manual/emacs.html
                     More info at:
                          http://www.emacswiki.org/cgi-bin/wiki
                          http://www.gnu.org/software/emacs/manual/
                          http://www.gnu.org/software/emacs/emacs-faq.html
C-h i                Show all manuals (not just Emacs) in Info reader
C-h r i topic Enter (or)
C-h i m emacs Enter i topic Enter
                     To quickly locate the section of the Emacs manual which
                     discusses a certain issue, or describes a command or
                     a variable, where topic is the name of the topic, the
                     command, or the variable which you are looking for. 
                     If this does not land you on the right place in the 
                     manual, press , (comma) repeatedly until you find what 
                     you need. (The i and , keys invoke the index-searching 
                     functions, which look for the topic you type in all the 
                     indices of the Emacs manual.)
M-x apropos          Find command, function, variable by regexp in name
                     (Same as C-h a)
M-x apropos-documentation
                     Find command, function, variable by regexp in docs
                     (Same as C-h d)
M-` (backtick)       Textual version of window's menu

C-u-C-x =            Show lots of ASCII/Unicode/etc info about current char

C-x m                Compose email

Aquamacs Emacs on Mac OS X
--------------------------
Cmd-Shift-Enter      Maximize/restore window size

Cmd-s                Save buffer
Cmd-w                Close frame/file
Cmd-q                Close editor
Cmd-Opt-Right/Left   Next/Previous buffer (only buffers w/notebook tabs)
Cmd-Shift-]/[        Next/Previous buffer (only buffers w/notebook tabs)
Fn-Up/Down           Page up/down
Fn-Left/Right        Home/End (of entire file, not line)
Cmd-Left/Right       Home/End of line
Cmd-i                Toggle Insert mode
Cmd-a                Select All
Cmd-c                Copy
Cmd-v                Paste
Cmd-x                Cut
Cmd-p                Print
Cmd-z                Undo
Cmd-Shift-z          Redo
Cmd-f                Find
Cmd-g                Find next
Cmd-m                Minimize to Dock or unminimize (toggle)
Cmd-l                Goto line number
Cmd-o                Open file
Cmd-Apostrophe       Comment out a line?
Cmd-Plus/Minus       Zoom bigger/smaller             
Opt-Scroll           Zoom bigger/smaller             
Cmd-2                Split current window top/bottom
Cmd-1                Single window
Cmd-Ctrl-Right/Left  Move right border of Mac window right/left
Cmd-Shift-t          Show/hide Mac Font Panel
Shift-F11            Toggle fullscreen
Cmd-Ctrl-f           Toggle fullscreen
Cmd-; (semicolon)    Spellcheck now
Cmd-: (colon)        Show spellcheck panel
Opt-r                Toggle between 3 locations
                     - Center of window
                     - Near top of window (5th line)
                     - Near bottom of window (6th from bottom)
                     - Like C-l but moves cursor, doesn't scroll

See also:
- http://www.stephenwalker.com/notes/aquamacsemacs-key-binding-list/
- https://www.gnu.org/software/emacs/refcards/pdf/refcard.pdf
- C-h key combinations shown above to list and describe keys and functions

Copyright 2008-2021, Bristle Software, Inc.  All rights reserved.