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.
vim |
Action.
Note: n generally defaults to 1 if not given.
Emacs: command is cursor movement. Emacs arguments, use ⎈U n or ⎇ 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 |
⎇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. |
⎈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 | ⎈N ⎇m | ⎈P ⎇m | |
h, ⎈H | l, <sp> | Move one column | ⎈F |
⎈B |
× |
$ |
0 |
Move to end or start of line | ⎈E |
⎈A |
× |
^ | 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 | ||||
nH |
nL |
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 |
⎇a |
|
} | { | Move by paragraph | ⎇} |
⎇{ |
|
]] | [[ | Move by section (default: formfeed delimited) ※ | ⎈X ] | ⎈X [ | |
Searching |
|||||
/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
⎆ |
⎈R
⎆ |
× |
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) |
|||
Marks ※ |
|||||
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: |
|||
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 |
⎇d |
⎇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 |
||||
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) |
⎈⎇O |
||||
Break line and indent like current line |
⎈⎇J |
||||
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 |
⎈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 |
⎇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 | ⎈_ or ⎈/ | × | |
. | Repeat last command †Emacs: continue repeating with z | ⎈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 | ||
Windows |
|||||
⎈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