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.

Vi & Vim Cheat Sheet - Essentials References

👉 Not sure between Vi and Vim? Check my post on the Differences Between Vi and Vim.

Insert & Replace

iinsert text before the cursor
ainsert text after the cursor
Iinsert text at the beginning of the current line
Ainsert text at the end of the current line
oinsert text in a new line below the cursor
Oinsert text in a new line above the cursor
rreplace a character at the cursor position
Rreplace 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
Ggoto the end of file
nG or :ngoto the line number n
0move to the beginning of the line
$move to the end of the line
CTRL+fmove one screen view forward
CTRL+bmove one screen view backward

Ex Commands

:qquit current open file
:q!force to quit without saving changes
:wsave file
:w filesave file as file
:wq!force to save file then quit
:x,yw filewrite from line x to line y into file
:w » fileappend buffer to file
:e fileedit another file
:e! fileedit another file without saving current changes
:r fileinsert file content at the current cursor position
:nedit next file in vi arguments file list
CTRL+Gdisplay current file name and position

Search & Substitute

/stringsearch forward for string
?stringsearch backward for string
nrepeat the last search
:,$s/str1/str2/gcsearch 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/greplace 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

uundo last change
CTRL+rredo last undo change
mAset mark A to current position. Marks can be the letter [a-z] and [A-Z]
y’Ayank (copy) from current line to mark A
d’Adelete from current line to mark A
Pput the buffer content before the cursor
pput the buffer content after the cursor
xdelete character at cursor position
dWdelete first word after cursor position
d$ or Ddelete from cursor position to end of line
dddelete current line
Jjoin current line with following line

Going Further

GET UNIQUE TIPS AND THE LATEST NEWS BY SUBSCRIBING TO MY NEWSLETTER.
AND FOLLOW ME ON