Last updated:
💻 Geeky Vibes! Check out our partner WrinkledT: Sustainable Style With a POP 💥 🌈 for the Soul (and the Planet!) 🌎💚

Have you ever felt slow working with Vi/Vim?

Vim is a free and open-source, screen-based text editor program inspired by Vi. It may be difficult for newcomers and even long-term users to remember all the different commands. This one-page cheat sheet 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 post covers the core essentials Vi & Vim cheat sheet, including brief references of Vi insert mode, edit commands, ex commands, navigation, search and substitute, etc. The cheat sheet is also available in an easy-to-print pdf and jpg format, or support this blog with the poster size Vi and Vim cheat sheet. You may also want to check my post on the Differences Between Vi and Vim.

Vi & Vim Cheat Sheet - Essentials References

👉 You have to use the ESC (escape key) to get into the vi command mode. You will need to press the RETURN Key for executing a command starting with the ponctuation character : or / or ?. Use CTRL+c to cancel a command. Use . to repeat your last command and :!cmd to execute a shell command (where cmd is the command to execute).

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

💻 Geeky Vibes! Check out our partner WrinkledT: Sustainable Style With a POP 💥 🌈 for the Soul (and the Planet!) 🌎💚
GET UNIQUE TIPS AND THE LATEST NEWS BY SUBSCRIBING TO MY NEWSLETTER.
AND FOLLOW ME ON