Show Menu

VI Editor Cheat Sheet by

vi

Controls

:w
Save
:x or :wq
Save & Exit
:q
Exit, is no changes
:q!
Exit, ignore any changes
:set ic
Ignore case while searching
:set noic
Case-s­ens­itive searching
:set nu
Turn on line numbers

Markers

mc
Set marker c on this line
`c
Go to beginning of marker c line
'c
Go to first non-blank character of marker c line

Navigation

h or
Move left
j or
Move down
k or
Move up
l or
Move right
w
Move to next word
W
Move to next blank delimited word
b
Move to the beginning of the word
B
Move to the beginning of the blank delimited word
e
Move to the end of the word
E
Move to the end of blank delimited word
0
Move to the beginning of the line
$
Move to the end of the line
1G or :0
Move to the first line in file
G or :$
Move to the last line in file
nG or :n
Move to the nth line in file
%
Move to associated (), {}, []
 

Inserting Text

i
Insert before cursor
I
Insert before line
a
Append after cursor
A
Append after line
o
Open a new line after current line
O
Open a new line before current line
r
Replace one character
R
Replace many characters

Deleting Text

x
Delete character to the right of cursor
X
Delete character to the left of cursor
D
Delete to the end of line
dd or :d
Delete current line
:%d
Delete all lines
:1,$d
Delete lines from beginning of file to end of current line
:x,yd
Delete lines x through y
ndw
Delete the next n words
ndb
Delete the previous n words
ndd
Delete n lines starting with current

Copy and Paste

yy or :y
Yank current line
y{motion}
Yank {motion} text
p
Put after the position or line
P
Put before the position or line

Changing text

C
Change to end of the line
cc
Change the whole line
guu
Lowercase line
gUU
Uppercase line
~
Toggle upper and lower case
 

Searching

/string
Search forward for string
?string
Search backwards for string
n
Go to next match
N
Go to previous match
*
Search for next instance of current word
#
Search for last instance of current word

Replacing

:s/pt/­str­/flag
Replace pattern with string
:% s/old/new
Replace all old with new
Flags
g
Replace all occurr­ences of pattern
c
Confirm replaces
&
Repeat last :s command

Other

u
Undo last change
U
Undo all changes to line
J
Join lines
nJ
Join next n lines
.
Repeat last command
>
Indent
<
De-indent

Other Navigation

(
Move a sentence back
)
Move a sentence forward
{
Move a paragraph back
}
Move a paragraph forward
fc
Move forward to c
Fc
Move back to c

Clean Up

:g/^$/d
Delete blank lines
:%s/­­\s\+$//
Delete trailing white space
:s/\s\+/ /g
Delete all extra white space between words

Download the VI Editor Cheat Sheet

1 Page
//media.cheatography.com/storage/thumb/adzz_vi-editor.750.jpg

PDF (recommended)

Alternative Downloads

Share This Cheat Sheet!

 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          VI Editor Cheat Sheet
            VI Editor / Linux Terminal Cheat Sheet by Smashing Magazine
          Vim Cheat Sheet