Show Menu
Cheatography

VI Cheat Sheet (DRAFT) by

This is a draft cheat sheet. It is a work in progress and is not finished yet.

How to Exit

:q[uit]
Quit Vim.
:q[uit]!
Quit without writing.
:wq
Write the current file and exit.
:wq!
Write the current file and exit always.
:wq {file}
Write to {file}. Exit if not editing the last
:wq! {file}
Write to {file} and exit always.
ZZ
Write current file, if modified, and exit.
ZQ
Quit current file and exit.

Inserting Text

a
Append text after the cursor [count] times.
A
Append text at the end of the line [count] times.
i
Insert text before the cursor [count] times.
I
Insert text before the first non-blank in the line [count] times.
gI
Insert text in column 1 [count] times.
o
Begin a new line below the cursor and insert text, repeat [count] times.
O
Begin a new line above the cursor and insert text, repeat [count] times.

Undo/R­edo­/Repeat

u
Undo [count] changes.
:u[ndo]
Undo one change.
CTRL-R
Redo [count] changes which were undone.
:red[o]
Redo one change which was undone.
U
Undo all latest changes on one line.
.
Repeat last change, with count replaced with [count].

Deleting Text

<De­l> or x
Delete [count] characters under and after the cursor
X
Delete [count] characters before the cursor
d{motion}
Delete text that {motion} moves over
dd
Delete [count] lines
{Visual}x or {Visual}d
Delete the highli­ghted text (for {Visual} see Selecting Text).
{Visual}X or {Visual}D
Delete the highli­ghted lines
:[range­]d[­elete]
Delete [range] lines (default: current line)
 

Searching

/{pattern}[/]
Search forward for the [count]'th occurrence of {pattern}
/{pattern}/{offset}
Search forward for the [count]'th occurrence of {pattern} and go {offset} lines up or down.
/<CR>
Search forward for the [count]'th latest used pattern
//{off­set­}<C­R>
Search forward for the [count]'th latest used pattern with new. If {offset} is empty no offset is used.
?{pattern}[?]<C­R>
Search backward for the [count]'th previous occurrence of {pattern}
?{pattern}?{offse­t}<­CR>
Search backward for the [count]'th previous occurrence of {pattern} and go {offset} lines up or down
?<C­R>
Search backward for the [count]'th latest used pattern
??{off­set­}<C­R>
Search backward for the [count]'th latest used pattern with new {offset}. If {offset} is empty no offset is used.
n
Repeat the latest "­/" or "­?" [count] times.
N
Repeat the latest "­/" or "­?" [count] times in opposite direction.