Vim Cheat Sheet: All you need to know about Vim keyboard shortcuts

It doesn’t matter if you are an experienced Vim user or a beginner — everyone can benefit from these handy Vim shortcuts that we’ve listed in this article.

Even though there are many graphical rich text editors out there, every Linux user can benefit from using Vim — a command-line-based tool that is actually an improved version of the venerable vi editor. And that goes for both new Raspberry Pi users and experienced system administrators.

An experienced operator can do wonders with this lightweight editor since it is quite powerful. Apart from providing regular text editing tasks, Vim also supports advanced features. Some of those include find and replace based on encoding conversion and regular expressions, as well as programming features such as code folding and syntax highlighting.

When you are using Vim, if you are in the “command mode” and you press the letter “j”, that will shift the cursor one line down. That happens because the function of a key depends on the mode the editor is in. So in order to make the keys input the character they represent, you’ll have to switch to the “insert mode”.

Now, here’s a list of common Vim shortcuts that will help you use Vim to its full potential.

Main

Escape key Get out of the mode you’re in and go into the “command mode”. All keys are bound by commands.
i Go into the “insert mode” to insert keys. All keys behave as you would expect.
: Go into “last-line mode” where Vim waits for you to insert a command; for example, to save a document.

Navigation keys

h Shift the cursor one character to the left
j or Ctrl + J Shift the cursor one line below
k or Ctrl + P Shift the cursor one line above
I Shift the cursor one character to the right
0 Shift the cursor to the start of the line
$ Shift the cursor to the end of the line
w Shift one word forward (the following alphanumeric word)
W Shift one word forward (delimited by white space)
5w Shift five words forward
b Shift one word backward (previous alphanumeric word)
B Shift one word backward (delimited by white space)
5b shift five words backward
G Shift to the end of the file
gg Shift to the start of the file

Navigating around the document

( Jump back to the previous sentence
) Jump to the following sentence
{ Jump to the previous paragraph
} Jump to the following paragraph
[[ Jump to the previous section
]] Jump to the following section
[] Jump to the end of the previous section
][ Jump to the end of the following section

Selecting text

v Go into the visual mode per character
V Go into the visual mode per line
Esc Get out of the visual mode

Inserting text

a Insert text after the cursor
A Insert text at the end of the line
i Insert text before the cursor
o Start a new line under the cursor
O Start a new line above the cursor

Deleting text

x Delete a character at the cursor
dw Delete one word
d0 Delete to the start of a line
d$ Delete to the end of a line
d) Delete to the end of a sentence
dgg Delete to the start of the file
dG Delete to the end of the file
dd Delete one line
3dd Delete three lines

Special inserts

:r [filename] Insert the file [filename] under the cursor
:r ![command] Execute [command] and insert its output under the cursor

Replacing simple text

r{text} Replace the character that’s under the cursor with {text}
R Instead of inserting characters, replace them

Copying/Pasting text

yy Copy the current line into the storage buffer
[“x]yy Copy current lines into register x
p Paste storage buffer after the current line
P Paste storage buffer in front of the current line
[“x]p Paste from register x after the current line
[“x]P Paste from register x in front of the current line

Modifying selected text

~ Switch the case
d Delete a word
c Change
y Yank
> Shift right
< Shift left
! Filter through an external command

Undoing/Redoing Operations

u Undo the last operation
Ctrl + r Redo the last undo

Searching and Replacing keys

/search_text Search the document for search_text going forward
?search_text Search the document for search_text going backward
n Move to the following instance of the result from the search
N Move to the previous instance of the result
:%s/original/replacement Search for the first incident of the string “original” and replace it with “replacement”
:%s/original/replacement/g Search and replace all incidents of the string “original” with “replacement”
:%s/original/replacement/gc Search for all incidents of the string “original” but ask for verification before replacing them with “replacement”

Bookmarks

m {a-z A-Z} Set bookmarks {a-z A-Z} at the current position of the cursor
:marks List all bookmarks
`{a-z A-Z} Jump to the bookmark {a-z A-Z}

Saving and Quitting

:q Quit Vim but not when a file has been changed
:w Saves the file
:w new_name Save the file with the new_name filename
:wq Save the file and quit Vim
:q! Quit Vim and don’t save the changes to the file
ZZ Write a file, if modified, and then quit Vim
ZQ Same as :q!; quit Vim without writing the changes

Have you found these Vim shortcuts helpful? Download the whole list and access it whenever you want!