emacs crib sheet

1 default behavior

C - Control M - Meta (alt)
Often refers to lines and characters; independent of your writing. Often words, paragraphs, sentences. Units of language.
C-x : eXtended commands M-x : named commands
C-v : move forward one screeen M-v : move backward one screen

1.1 navigation

C-l : clear + move screen to center on cursor
C-l C-l : Move the line the cursor is on to the top of the screen
C-l (repeat) : Toggles between moving the current line to the center>top>bottom of the screen, cyclically.

     C-p                 C-p : previous line
      ^                  C-n : next line
C-b <-|-> C-f            C-b : back (space)
      v                  C-f : forward (space)
     C-n

M-b <---> M-f            M-b : back (word)
                         M-f : forward (word)

C-a : beginning of line
C-e : end of line
M-< : beginning of document
M-> : end of document


1.2 general

C-u [number] [command]
or
M-[number] [command] : repeat [command] [number] times
C-x k : kill buffer
C-g : safely stop emacs or a command
electric behavior : when pressing a key does more than insert the character pressed (fornatting, tab filling, etc.)
C-k : delete to the end of the current line
M-k : delete to the end of the current sentence
C-[spc] : highlight chunk of text
C-w : kill the highlighted text
'Killed' text is not deleted. You can reinsert it by 'yanking' it from the killed space.
C-k : kill current line
C-y : yank killed lines
Multiple lines will be yanked together if killed consecutively.
C-/ : undo
C-_ : undo
C-x u : undo

C-u [number] C-v
or
C-u [number] M-v : move forward or backward [number] lines


1.3 files

C-x C-f : find and open file in new buffer
C-x C-s : save
C-x C-b : list buffers
C-x b : switch to other buffer
C-x C-c : end session, asking to save changes
in terminal: C-z : suspend emacs. Return with fg or %emacs
find and replace: M-x [string] : asks for search, then text to replace.
Note: named commands can be tab or [spc] completed.

Autosave data is by default saved in the same directory as the file, flanked by pound signs. Ex: hello.c -> #hello.c#
M-x recover-this-file


1.4 windows

C-x 1 : kill all windows except the active one containing the cursor.
C-x 2 : split in two windows
C-x 0 : move to 'other' window
[esc] C-v : scroll lower window
C-x 4 C-f : open file in lower window
C-x 3 : split window right
C-x 2 : split window bel


frames
C-x 5 2 : create new frame
C-x 5 0 : delete current frame
C-x 5 1 : delete all other frames


recursive edit level<
[esc] x3 : kill minibuffer (M-x, for instance.)


1.5 searching

C-s : displays incremental search. C-s again moves to the next match. [return] to exit.
C-r : incremental reverse search


1.6 help

C-h ? : big help
C-h c : simple help for a term
C-h k : documentation for a command
C-h f : documentation for a function
C-h m : info on current mode


edit modes
M-x : text mode (' now part of word)

  • indicates unsaved changes are present

M-x : auto-fill-mode
C-u [number] C-x f : change autofill column width to [number]
M-q : auto refill a paragraph


2 more advanced tricks

C-x + / C-x - : make the font bigger /smaller
C-x [right] / C-x [left] : move to the next / previous buffer
[highlight block] M-; : comment / uncomment highlighted text

2.1 Macros

C-x ( : begin macro
C-x ) : end macro
C-x e : perform macro

3 Tramp

Sometimes when working with a remote document using Tramp, you will want to open a local file. C-f will not let you navigate to local directories in any obvious way. You can do this by navigating to a directory with
ssh:remote-system/~~
This will change your current browsing path to home on your local machine.