wlindley.com, l.l.c.
Computer Guru for Hire.
Have Keyboard, Will Travel.



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

With default Readline bindings for bash shell.
vim
Action. Note: n generally defaults to 1 if not given.
Emacs: command is cursor movement.
Emacs arguments, use ^U n or Alt n
emacs
bash (readline)
Forward Backward Forward
Backward
(×=as emacs)

S C R O L L I N G

^E ^Y Scroll by line


^D ^U Scroll by half page


^F ^B Scroll by page ^V
Alt+v

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

M O V E M E N T

j, ^N, ^J k, ^P Move one line ^N
^P
×
+ - Move one line, to first nonblank


h, ^H l, <sp> Move one column ^F
^B
×
$
0
Move to end or start of line ^E
^A
×
^  Move to first nonblank column Alt+m

n|  Move to column n

nG  Move to line n or EOF if n not given Alt+G n

Esc 1 G G Move to end or start of buffer
Alt+>
Alt+<
×
H, M, L  Position top, middle, bottom

nH
nL 
Position n lines past top or before bottom



Movement by content

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


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


) ( Move by sentence Alt+e
Alt+a

} { Move by paragraph Alt+}
Alt+{

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


Searching

/pattern ?pattern Search for pattern ^S pattern
^R pattern
×
n N Search again in same (n) or opposite (N) direction ^S <enter>
^R <enter>
×

Searching on current line

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)

Marks

mx  Set mark x ^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


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).
^space


Editing

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>
×
dw
Delete word
Alt+d
Alt+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
^X^O


nJ, gnJ
Join next line (n lines) to end of current. (use g to omit spaces) ^E^D  

Join this line to previous and compress whitespace at join.
Alt+^



Move rest of line down (break and indent to current column)
^Alt+O



Break line and indent like current line
^Alt+J


n~ Toggle upper/lower case for n characters.



UPPERCASE, Capitalize, lowercase current word Alt+u, Alt+c, Alt+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} Alt+w
×
Y  Copy current line ^A ^space ^E Alt+w

p P Paste text (from Copy or Delete/Cut) after (P before) cursor
^Y

×
" n Prefix for y, Y, p, or P to operate on register n.  

Paste text without moving cursor
^U^Y



Replace last pasted text with previous entry from kill ring
Alt+Y

×
  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 ^_
×
.  Repeat last command ^X z


Abort current command
^G ×

Files

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


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

Courtesy wlindley.com and Phoenix Linux Users Group ( http://plug.phoenix.az.us )
May be freely distributed.  rev 2007-06-27