A collection of Vim commands in a cheat sheet, handy reference document for learning / remembering Vi commands. I refer to Vim / Vi as the same thing in this document, but in most modern Linux distros vi is often a symlink to vim. However, you may want to check out Neovim if you’re on a mac use brew install neovim or your package manager of choice on Linux.

Mac users will need to swap Ctrl for CMD, and deal with the additional annoyance of using their thumbs instead of their pinkie finger.

Vim Insert mode & Command Mode

Vim has two basic modes, insert mode - used for entering text and command mode, used for entering commands. See the tip section below for switching between each mode.

Vim Insert Mode

Enter vi insert mode, insert mode is used for inserting text.

Vim Command Description

i

Enter insert mode from command mode.

Vim Command Mode - Vim Insert Mode

Vim has two modes, insert mode for inserting text and command mode a common mistake is attempting to edit in command mode. If you are unsure on what mode Vim is using double tap escape (enters command mode) and then hit "i" if you wish to enter insert mode.

Vim Command Mode

Vim Command Description

Esc

Hit escape to enter command mode.

Vim File Navigvation

Basic file navigation, how to move up, down, left and right.

Arrow Keys

Modern Vim / Vim editors will allow you to use the arrow keys, but it's worth learning the correct way to navigate vi without using the arrow keys in case you come across Vim command line or a shell that doesn't like arrow keys.

Move up, down, left and right in Vim

You’ll need to be in command mode for these commands, navigation in vim uses h j k l

Vim Command Description

h

Move left - easy to remember h key is on the left

j

Move down - I remember it with j(d)own for down

k

Move up - k for up - I remember it with (k)up

l

Move right - l is on the right side of hjkl and moves you right

Vim Page Down

Vim Command Description

Ctrl+F

Vim move forward a page

Vim Half a Page Down

Vim Command Description

Ctrl+D

Vim move half a page down

Vim Page Up

Vim Command Description

Ctrl+B

Vim move up a page

Vim Half a Page Up

Vim Command Description

Ctrl+U

Vim move up half a page

More Advanced Ways of Entering Insert Mode

Vim Insert Text at Start of the Line

Vim Command Description

I

Insert text at the beginning of the line

Vim Insert Text at the end of the Line

Vim Command Description

A

Appends text at the end of the line

Vim Append text to the right of the Cursor

Vim Command Description

a

Appends text to the right of the cursor

Begin a new line below

Vim Command Description

o

Begin a new line, below the current line

Vim replace line

Vim Command Description

O

Removes line, and allows you to type a new line in it's place

Vim Replace

Change a Word in Vim

Vim Command Description

cw

Replaces a single word, place cursor on first letter and hit cw (Change Word)

Replace line, but not wrapped text

Vim Command Description

c$

Replaces the current line but doesn’t extend to change the rest of a wrapped sentence on the screen

Vim Replace Character

Vim Command Description

r

Replaces only the character under the cursor

Vim Replace

Vim Command Description

R

Replaces over the top of existing text, until the user hits return.

Vim Delete

Vim Delete Single Character After the Cursor

Vim Command Description

x

Vim deletes single character after the cursor

Vim Delete Character before the Cursor

Vim Command Description

X

Vim deletes character before the cursor.

Vim Delete Word

Vim Command Description

dw

Vim Delete Word, deleted the word under the cursor, from the curosr position onward

Vim Delete Line commands

Vim Delete Line

Vim Command Description

dd

Delete the current line in Vim

Vim Delete until end of Line

Vim Command Description

D

Deletes from cursor to end of line

Delete to end of screen

Vim Command Description

dL

Deletes from cursor to end of screen

Delete to end of file

Vim Command Description

dG

Deletes from cursor to end of file

Vim Delete From Cursor To Start of Line

Vim Command Description

d^

Deletes from cursor to start of line

Vim Copy and Paste

Vim Copy Line

Vim Command Description

yy

Copies current line into unnamed buffer

Vim Copy 3 Lines of Text

Vim Command Description

3yy

Copy 3 lines of text into unnamed buffer

Vim Copy Word

Vi Command Description

yw

Copy word under cursor into unnamed buffer

Vim Copy 3 Words

Vim Command Description

3yw

Copy 3 words into unnamed buffer

Vim Paste Commands

Vim Command Description

P

Copy contents of unamed buffer to right of cursor

Vim Command Description

p

Copy contents of unamed buffer to left of cursor

Vim Search Commands

Vim Search forward

Vim Command Description

N

Vim search forward in file

Vim Search Back

Vim Command Description

SHIFT+N

Vim search backward in file

Vim Search and Replace Commands

Vim Search and Replace First Instance

Vim Command Description

:s/find-string/replace-string/

Vim search and replace first instance of specified string

Vim Search and Replace on a Single Line

Vim Command Description

:s/find-string/replace-string/g

Vim search and replace all instances of specified string on current line

Vim Search and Replace Entire File

Vim Command Description

:%s/find-string/replace-string/g

Vim search and replace all instances of specified string for entire file

Vim Search for part of a Word

A fuzzy search allows you to find something that you only know part of, for example if you wanted to find all instances of lines starting with the word “Picard” you would use the following:

Vim Command Description

/^Picard

Vim search within file words starting with Picard

Vim Search for words ending with $string

Vim Command Description

/worf$

Vim search within file for word engine with worf

Vim Search for Metacharacters

Vim Command Description

/\*

Vim search within file for metacharacters like, *

Vim Exact Match Search Only

Vim Command Description

/star\.

Vim exact search only, will return instances of "star only", not starfleet or star-trek

Vim Search for a range of Strings

Helpful for finding version numbers in text files.

Vim Command Description

/v2.[1-9]

Vim search for a range, this example would return all v2.1-9 instances within the file, e.g. v2.4 v2.7 etc

Vim Search for Upper and Lowercase

Search for upper and lowercase strings in Vim.

Vim Command Description

/ [tT] [hH [eE]

Vim search upper or lowercase strings, this example would return any instance of the word 'the'. e.g. The, THE, tHE, tHe

Advanced Vim commands

Vim View Options

Vim Command Description

:set all

Lists all Vim options

Vim Run Shell Commands

Run shell commands from Vim.

Vim Command Description

:! ls -l

Run shell command from Vim, in this example ls -l is executed

Vim Joining Lines

Backspace doesn’t always work…

Vim Command Description

SHIFT+J

Position the cursor in either line you wish to join, and press SHIFT+J

Vim Split Windows

Useful for comparing files, to switch between windows press SHIFT+W

Vim Split Window Horizontally

Vim Command Description

:split

Split window Horizontally in Vim

Vim Split Window Virtically

Vim Command Description

:vsplit

Split window Virtically in Vim

Vim Close All Split Windows

Vim Command Description

:only

Closes all split windows and focuses on the primary window

Vim Save commands

How to Save in Vim

Vim Command Description

:w

Writes the file to disk

Vim Save and Exit

How to save and exit Vim, personally I use :wq

</tr> </tr> </tr>
Vim Command Description

:wq

Save and exit Vim

:x

Exit - Vim will prompt and ask if you wish to save

SHIFT+ZZ

Another way to Save and Exit Vim

wq!

Forces save on read only files, and exits

Misc Vim Commands

Vim Undo Command

Vi Command Description

U

Press SHIFT+U to undo in Vi

Vim Undo All

Vim undo all since last write.

Vim Command Description

:+X+!

Undo everything since last write

Vim Show File Name

SHIFT+G shows the file name, number of lines and current position.

Vim Multipliers

Almost every command in Vim can leverage multipliers, typically it’s a case of prefixing the command with a numnber. Example: 10W would move 10 words to the right.