A vim command cheat sheet for beginners


I have noted that there are a number of VIM commands that are essential for VIM beginners.  There are several good beginners guide to use VIM, vim tutorials and vim cheat sheets but never the less here are a few of them that I’ve found to be good to know..

File commands

Command Description / Usage
:q To quit vim. If you have made changes then you can type ’:q!’ to quit without saving the changes. This can be combined with the write command like ’:wq’ which saves and then quits vim.
:w To write/save the current changes you need to type ’:w’. You can specify to which file to save to by typing ’:w <file>’.
:e To edit/open a file. By typing ’:e .’ you get a directory listing in which you can select a file to edit.
:! To execute a command line command. E.g. if you type ’:!ls’ then you’ll list information about the current directory.

Movement commands

Most of these commands can be prefixed with a number (n) to repeat the command a given number of times. E.g. see H and L in the table below.

Command Description / Usage
k To move up.
j To move down.
l To move right.
h To move left.
H To the top of the screen. If you e.g. type ’3H’ then you’ll jump to the third line below the top of the screen.
L To move to the bottom of the screen. If you e.g. type ’3L’ then you’ll jump to the third line above the bottom of the screen.
g To move to the beginning of the file.
G To move to the end of the file.
Ctrl + G To get the file status. You’ll get the name of the file, the number of rows in it and at which line you are at (in per cent of the total number of rows).
^ To move to the beginning of the row.
$ To move to the end of the row.
:n To move to row n. Note that n should be a number. E.g. ’:10’ moves to row 10.
Ctrl + f To move one screen forward.
Ctrl + b To move one screen back.
[{ To move to the beginning of a block.
]} To move to the end of a block.

Search Commands

Command Description / Usage
/<some string> To do a (forward) search for some string. E.g. to find ”foo” in the text type ’/foo’.
? Same as / but backwards.
n Find next.
N Find previous.
%s/foo/bar/g as

Edit commands

Command Description / Usage
dd To delete the current line
dw To delete the first word after the cursor.
u To undo last change
y To yank/copy the marked text
V To mark a row (then use arrows to mark multiple rows). When marked press y to copy or d to delete.
Ctrl + V To mark a block. As with ’V’ use arrow keys to mark and then y to copy or d to delete.

That is it for now. There are much more that can be found by e.g. goggling vim + tutorial.