Vi and Vim Quick References: A One Page Cheat Sheet
Last updated:
Have you ever felt slow working with Vi/Vim?
Check this one-page cheat sheet that will help you get back to work quickly and improve your velocity while working in Vi/Vim:
Vi & Vim Cheat Sheet in PDF format
This is a core essentials Vi & Vim cheat sheet which cover the basic quick references of Vi insert mode, edit commands, ex commands, navigation, search and substitute, etc.
replace characters starting at the cursor position
Cursor Motion
h or ←
move cursor left
l or →
move cursor right
k or ↑
move cursor up
j or ↓
move cursor down
G
goto the end of file
nG or :n
goto the line number n
0
move to the beginning of the line
$
move to the end of the line
CTRL+f
move one screen view forward
CTRL+b
move one screen view backward
Ex Commands
:q
quit current open file
:q!
force to quit without saving changes
:w
save file
:wfile
save file as file
:wq!
force to save file then quit
:x,ywfile
write from line x to line y into file
:w »file
append buffer to file
:efile
edit another file
:e!file
edit another file without saving current changes
:rfile
insert file content at the current cursor position
:n
edit next file in vi arguments file list
CTRL+G
display current file name and position
Search & Substitute
/string
search forward for string
?string
search backward for string
n
repeat the last search
:,$s/str1/str2/gc
search and substitute str1 by str2 from the current line to the end of file. A line number can be specified before the comma “,”. The “c” ask for confirmation before each substitution
:%s/str1/str2/g
replace all str1 by str2 in all the file without prompting for confirmation
:%s/str1/str2/
replace str1 by str2 on the first occurrence in each line of the file
Undo, Delete, and Copy
u
undo last change
CTRL+r
redo last undo change
mA
set mark A to current position. Marks can be the letter [a-z] and [A-Z]
y’A
yank (copy) from current line to mark A
d’A
delete from current line to mark A
P
put the buffer content before the cursor
p
put the buffer content after the cursor
x
delete character at cursor position
dW
delete first word after cursor position
d$ or D
delete from cursor position to end of line
dd
delete current line
J
join current line with following line
Going Further
:map for mapping a key in command mode to a group of commands. Example: :map de :1,$d^M will delete all
lines when using the :de command.
:set to define or show your editor options. Example: :set number will make vi display line numbers, and
“:set all” will display all current vi options.
:ab to define a text abbreviation in insert mode. Example: :ab VIM Vi Improved will auto-complete “VIM”
in insert mode for the phrase “Vi Improved”.
GET UNIQUE TIPS AND THE LATEST NEWS BY SUBSCRIBING TO MY NEWSLETTER.