A quick start guide for beginners to the VIM text editor

  • By Christopher Kielty, last updated September 07, 2016
  • Filed under: Linux Ubuntu Mac
VIM cheat sheet

Basic functionality

With a command line window open, navigate to the directory where you want to create a new text document. Then start VIM with the name of the file you want to edit.

vim file.txt

If the file exists, VIM opens it. If the file doesn’t exist, VIM creates it in the current directory and opens it.

VIM has multiple modes. When first started, VIM is in command mode. Various editing tasks can be performed from command mode. However, at this point you'll likely want to insert text. To do this, enter insert mode by hitting i. Get back out of insert mode by hitting esc

VIM insert mode

Notice the “1,44” in the bottom right of the screen. 1 indicates the line number while 44 indicates the character number on that line.

Try switching between command and insert mode a few times with i and esc. This might seem like a lot of fuss for just entering some text in a file. The usefulness of command mode will become apparent in a few moments.

To exit VIM, first make sure you're in command mode (esc). To quit without saving: :q!. To save the current document and exit: :wq.

Editing with command and visual mode

Delete one word dw
Delete the whole line dd

In VIM, when you delete something, you’re actually cutting it. To paste, use either lower or upper case P.

Paste just below cursor p (lower case)
Paste just after cursor P (upper case)

If you wanna select some text, then copy/cut/delete it, use visual mode.

Enter visual mode v
Copy (yank) selected text y
Delete/cut selected text d
Undo changes u.
Redo control + r

Moving around with command mode

Arrow keys work just fine in command/visual mode and in insert mode. However, if you want to move around a VIM document with a little less effort, here are the keys to do it.

Move forward one word w
Move backward one word b
Move to the beginning of the current line 0
Move to the end of the current line $
Move forward one sentence )
Move back one sentence (
move to the top of the document gg
Move to the bottom of the document G
Move to the last thing that was edited in the document `.
Center the screen on cursor z.