emacs: movement

Moving by character

Four fundamental movement

Key Binding Purpose
C-f Move forward by character
C-b Move backward by character
C-p Move to previous line
C-n Move to next line

Moving by line

Key Binding Purpose
C-a Moves point to the beginning of the line
C-e Moves point to the end of the line
M-m Moves point to the first non-whitespace character on this line

Moving by word

Key Binding Purpose
M-f Move forward by word
M-b Move backward by word

Subword and superword movement

Command Purpose
M-x subword-mode Minor mode that treats CamelCase as distinct words
M-x superword-mode Minor mode that treats snake_case as one word

Moving by s-expression

Key Binding Purpose
C-M-f Move forward by s-expression
C-M-b Move backward by s-expression

Down and up List

Key Binding Purpose
C-M-d Move down into a list
C-M-u Move up out of a list

Forward and backward list

Key Binding Purpose
C-M-n Move forward to the next list
C-M-p Move backward to the previous list

Other movement commands

Moving by Paragraph

Key Binding Purpose
M-} Move forward to end of paragraph
M-{ Move backward to start of paragraph

a set of variables that define the beginning and end of a paragraph:

Variable Name Purpose
paragraph-start Defines the beginning of a paragraph using a large regular expression
paragraph-separate Defines the paragraph separator as a regular expression
use-hard-newlines Set by the command M-x use-hard-newlines and defines whether a hard newline defines a paragraph

Moving by sentence

Key Binding Purpose
M-a Move to beginning of sentence
M-e Move to end of sentence

You can alter this behavior by customizing (with M-x customize-option) the following variables:

Variable Name Purpose
sentence-end-double-space Non-nil means a single space does not end a sentence
sentence-end-without-period Non-nil means a sentence will end without a period
sentence-end-without-space A string of characters that end a sentence without requiring spaces after

Moving by Defun

Key Binding Purpose
C-M-a Move to beginning of defun
C-M-e Move to end of defun

Moving by Pages

Key Binding Purpose
C-x ] Moves forward one page
C-x [ Moves backward one page

Scrolling

Key Binding Purpose
C-v Scroll down one page
M-v Scroll up one page
C-M-v Scroll down the other window
C-M-S-v Scroll up the other window

In Mac iterm2, you should use M-PageUp and M-PageDn to scroll the other window.

Move to begin and end

Key Binding Purpose
M-< Move to the beginning of the buffer
M-> Move to the end of the buffer

When you move to the beginning or end of the buffer, Emacs will place the mark – an invisible location marker – where you came from, so you can return to your old position. For instance, if you type M-< to jump to the beginning of the buffer, you can type C-u C-<SPC> to go back.

Numeric arguments

Move down 50 lines

1
M-5 0 C-n

C-u alone has the special meaning of “four times”, moves forward sixteen characters

1
C-u C-u C-f