wlindley.com, l.l.c.

William Lindley — Jacksonville, Florida

vim (vi) and emacs: "Rosetta Stone" Quick Reference

A "Cheat Sheet." Also includes default Readline bindings for bash shell.
NOTE: This guide now uses the Unicode and ISO standard characters:
⇧ for shift, ⎈ for Ctrl, ⎇ for Meta or Alt, and ⎆ for Enter.
Also NOTE: Alt-space is usually trapped by XWindows, thus the sequence Esc-space is shown in the Editing section.
Action. Note: n generally defaults to 1 if not given.
Emacs: command is cursor movement.
Emacs arguments, use ⎈U n or n
bash (readline)
Forward Backward Forward
(×=as emacs)


⎈E ⎈Y Scroll by line

⎈D ⎈U Scroll by half page

⎈F ⎈B Scroll by page ⎈V

z<cr>  z.  z-  redraw; place current line at top of screen
(z. in middle, z- at bottom).
emacs: ⎈L alternates middle, top, bottom.


j, ⎈N, ⎈J k, ⎈P Move one line ⎈N
+ - Move one line, to first nonblank ⎈N ⎇m ⎈P ⎇m
h, ⎈H l, <sp> Move one column ⎈F
Move to end or start of line ⎈E
^  Move to first nonblank column ⎇m

n|  Move to column n ⎇G TAB n

nG  Move to line n or EOF if n not given ⎇G ⎇G n

Esc 1 G G Move to end or start of buffer
H, M, L  Position top, middle, bottom

Position n lines past top or before bottom

Movement by content

w b Move by word ⎇f
⎇b ×
W B Move by blank-delimited word

e, E   Forward to end of word (E blank-delimited)

) ( Move by sentence ⎇e

} { Move by paragraph ⎇}

]] [[ Move by section (default: formfeed delimited) ⎈X ] ⎈X [


/pattern ?pattern Search for pattern NOTE: Emacs searches are incremental ⎈S pattern
⎈R pattern
n N Search again in same (n) or opposite (N) direction ⎈S
In Isearch, edit search string non-incrementally ⎇E
    Search for regular expression ⎇⎈S regex
⎇⎈R regex
    Create buffer: all occurrences of regular expression ⎇S o regex  
    In Isearch, create occur buffer using search string as regex ⎇S o  
fchar Fchar Search for character on current line

tchar Tchar Position before character on current line

; , Repeat character search on current line

%  Find matching brace (automatic)


mx  Set mark x (emacs: global mark) ⎈space
`` '' Move to previous mark; move to start of prev mark's line ⎈X⎈X
`x 'x Move to mark x; to start of markx's line

    Move to previous mark from mark ring ⎈U ⎈space
V ⎈V Set mark and enter visual (V) or visual block (⎈V) mode.
NOTE: vi commands on visual area include:
~, d, p (put), y (yank), Y (yank whole lines).


a i Insert new text after (i before) cursor

A I Insert at end (I beginning) of current line

o O Open new line after (O before) cursor ⎈O

r, R Replace one character; Enter Replace mode

x X Delete character under (X to left of) cursor ⎈D
Delete word
⎇BS ×
d{command}  Delete (cut) text in region or spanned by command ⎈space {command} ⎈W
c{command}  Change - c is like d{command}i

nD, nC
Delete, Change to start or end of line (and n-1 more lines) ⎈K

⎈X BS (to start)

Delete blank lines around cursor

Delete all whitespace at cursor ⎇\

Replace any whitespace at cursor with exactly one space <Esc> <space>

nJ, gnJ
Join next line (n lines) to end of current. (g omits spaces) ⎈E⎈D  

Join this line to previous and compress whitespace at join.

Move rest of line down (break and indent to current column)

Break line and indent like current line

Indent (negative n outdent) region by n columns ⎈U n ⎈X ⎈I

n~ Toggle upper/lower case for n characters.

UPPERCASE, Capitalize, lowercase current word ⎇u, ⎇c, ⎇l ×

Copy & Paste (see Delete above for Cut)

y{command}  Copy region or text spanned by command
vi: in visual mode, omit command and operate on region.
⎈space {command} ⎇w
Y  Copy current line ⎈A ⎈space ⎈E ⎇w

p P Paste text (from Copy or Delete/Cut) after (P before) cursor
" n Prefix for y, Y, p, or P to operate on register n.  

Paste text without moving cursor

Replace last pasted text with previous entry from kill ring
  Copy to register n. (With argument, also delete.) ⎈x r x n
  Insert contents of register n. ⎈x r i n
u U Undo last command, commands on a line ⎈_ or ⎈/ ×
.  Repeat last command †Emacs: continue repeating with z ⎈X z

Abort current command
⎈G ×


:w :z Save; Save and Exit ⎈X⎈S ⎈X⎈S ⎈X⎈C
:q :q! Quit (vi :q! quits without saving) ⎈X⎈C


⎈Ws ⎈Wv Split Window Horizontally; Vertically ⎈X2 ⎈X3
⎈Ww ⎈Wq Switch windows; Close current window ⎈Xo ⎈X0 [zero]
Close all other windows ⎈X1
⎈W> ⎈W< Make current window wider; narrower ⎈X} ⎈X{
⎈W+ ⎈W– Make current window taller; shorter ⎈X^ ⎈U-1⎈X^
    Fit current window to contents ⎈X+  

See also: the official ※ GNU Emacs manual and the participatory Emacs wiki.

Courtesy wlindley.com
May be freely distributed.  rev 2015-02-06