CPSC120A: Fundamentals of Computer Science
Fall 2011: Emacs Commands

Navigating

C-f            move cursor forward
C-bmove cursor backward
C-nmove cursor to next line
C-pmove cursor to previous line
M-fmove cursor forward one token
M-bmove cursor backward one token
C-lcenter screen on cursor
C-amove cursor to beginning of line
C-emove cursor to end of line
M-x goto-linego to line
C-vmove down one screenful
M-vmove cursor up one screenful
M-<move cursor to beginning of buffer
M->move cursor to end of buffer

Editing

M-/auto complete
M-qfill paragraph (useful for wrapping lines in comments)

Buffers and Windows

C-x C-ffind file (open in current buffer)
C-x C-blist existing buffers
C-x bselect buffer by name
C-x 2split current window in two vertically
C-x 3split current window in two horizontally
C-x 0delete the current window
C-x 1delete all windows but the current
C-x oswitch to other window
C-M-vscroll other window down

Searching

C-sforward incremental search
C-rreverse incremental search
<RET> (when in search mode)stop searching
C-g (when in search mode)cancel search and return to where search started
M-y (when in search mode)yank most recent kill into seach string
M-% search_string <RET> replace_string <RET>query replace occurances of search_string with replace_string
y (when in query replace mode)replace highlighted search_string
<SPACE> (when in query replace mode)do not replace highlighted search_string
q (when in query replace mode)exit query replace mode
M-x grep <RET> search_string file_name1 file_name2 ... search for search_string in the specified files (note the files do not have to be currently open)
M-x grep <RET> search_string * search for search_string in all files in the current directory
C-x `select next search_string in grep buffer

Compiling and Running

M-x compilerun compile command in other window
C-x `select next error in compile buffer
M-x shellopen shell in this window
M-pprevious command (while cursor is at the command prompt in the shell
C-c C-ckill currently running program (while in the shell

Configuring

The following can be put in the ~/.emacs.d/init.el file to configure Emacs

(set-face-attribute 'default nil :height FONT_SIZE)Where FONT_SIZE is the initial font size of Emacs window times ten.
(setq default-frame-alist '((width . CHARS_WIDE) (height . CHARS_HIGH)))Where CHARS_WIDE and CHARS_HIGH are the initial dimensions of Emacs windows in terms of characters.