- Vim Insert mode & Command Mode
- Vim File Navigvation
- More Advanced Ways of Entering Insert Mode
- Vim Replace
- Vim Delete
- Vim Delete Line commands
- Vim Copy and Paste
- Vim Search Commands
- Vim Search and Replace Commands
- Vim Search and Replace First Instance
- Vim Search and Replace on a Single Line
- Vim Search and Replace Entire File
- Vim Search for part of a Word
- Vim Search for words ending with $string
- Vim Search for Metacharacters
- Vim Exact Match Search Only
- Vim Search for a range of Strings
- Vim Search for Upper and Lowercase
- Advanced Vim commands
- Vim Save commands
- Misc Vim Commands
- Vim Show File Name
- Vim Multipliers
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 |
---|---|
|
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 |
---|---|
|
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 |
---|---|
|
Move left - easy to remember h key is on the left |
|
Move down - I remember it with j(d)own for down |
|
Move up - k for up - I remember it with (k)up |
|
Move right - l is on the right side of hjkl and moves you right |
Vim Page Down
Vim Command | Description |
---|---|
|
Vim move forward a page |
Vim Half a Page Down
Vim Command | Description |
---|---|
|
Vim move half a page down |
Vim Page Up
Vim Command | Description |
---|---|
|
Vim move up a page |
Vim Half a Page Up
Vim Command | Description |
---|---|
|
Vim move up half a page |
More Advanced Ways of Entering Insert Mode
Vim Insert Text at Start of the Line
Vim Command | Description |
---|---|
|
Insert text at the beginning of the line |
Vim Insert Text at the end of the Line
Vim Command | Description |
---|---|
|
Appends text at the end of the line |
Vim Append text to the right of the Cursor
Vim Command | Description |
---|---|
|
Appends text to the right of the cursor |
Begin a new line below
Vim Command | Description |
---|---|
|
Begin a new line, below the current line |
Vim replace line
Vim Command | Description |
---|---|
|
Removes line, and allows you to type a new line in it's place |
Vim Replace
Change a Word in Vim
Vim Command | Description |
---|---|
|
Replaces a single word, place cursor on first letter and hit cw (Change Word) |
Replace line, but not wrapped text
Vim Command | Description |
---|---|
|
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 |
---|---|
|
Replaces only the character under the cursor |
Vim Replace
Vim Command | Description |
---|---|
|
Replaces over the top of existing text, until the user hits return. |
Vim Delete
Vim Delete Single Character After the Cursor
Vim Command | Description |
---|---|
|
Vim deletes single character after the cursor |
Vim Delete Character before the Cursor
Vim Command | Description |
---|---|
|
Vim deletes character before the cursor. |
Vim Delete Word
Vim Command | Description |
---|---|
|
Vim Delete Word, deleted the word under the cursor, from the curosr position onward |
Vim Delete Line commands
Vim Delete Line
Vim Command | Description |
---|---|
|
Delete the current line in Vim |
Vim Delete until end of Line
Vim Command | Description |
---|---|
|
Deletes from cursor to end of line |
Delete to end of screen
Vim Command | Description |
---|---|
|
Deletes from cursor to end of screen |
Delete to end of file
Vim Command | Description |
---|---|
|
Deletes from cursor to end of file |
Vim Delete From Cursor To Start of Line
Vim Command | Description |
---|---|
|
Deletes from cursor to start of line |
Vim Copy and Paste
Vim Copy Line
Vim Command | Description |
---|---|
|
Copies current line into unnamed buffer |
Vim Copy 3 Lines of Text
Vim Command | Description |
---|---|
|
Copy 3 lines of text into unnamed buffer |
Vim Copy Word
Vi Command | Description |
---|---|
|
Copy word under cursor into unnamed buffer |
Vim Copy 3 Words
Vim Command | Description |
---|---|
|
Copy 3 words into unnamed buffer |
Vim Paste Commands
Vim Command | Description |
---|---|
|
Copy contents of unamed buffer to right of cursor |
Vim Command | Description |
---|---|
|
Copy contents of unamed buffer to left of cursor |
Vim Search Commands
Vim Search forward
Vim Command | Description |
---|---|
|
Vim search forward in file |
Vim Search Back
Vim Command | Description |
---|---|
|
Vim search backward in file |
Vim Search and Replace Commands
Vim Search and Replace First Instance
Vim Command | Description |
---|---|
|
Vim search and replace first instance of specified string |
Vim Search and Replace on a Single Line
Vim Command | Description |
---|---|
|
Vim search and replace all instances of specified string on current line |
Vim Search and Replace Entire File
Vim Command | Description |
---|---|
|
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 |
---|---|
|
Vim search within file words starting with Picard |
Vim Search for words ending with $string
Vim Command | Description |
---|---|
|
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 |
---|---|
|
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 |
---|---|
|
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 |
---|---|
|
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 |
---|---|
|
Lists all Vim options |
Vim Run Shell Commands
Run shell commands from Vim.
Vim Command | Description |
---|---|
|
Run shell command from Vim, in this example ls -l is executed |
Vim Joining Lines
Backspace doesn’t always work…
Vim Command | Description |
---|---|
|
Position the cursor in either line you wish to join, and press |
Vim Split Windows
Useful for comparing files, to switch between windows press SHIFT+W
Vim Split Window Horizontally
Vim Command | Description |
---|---|
|
Split window Horizontally in Vim |
Vim Split Window Virtically
Vim Command | Description |
---|---|
|
Split window Virtically in Vim |
Vim Close All Split Windows
Vim Command | Description |
---|---|
|
Closes all split windows and focuses on the primary window |
Vim Save commands
How to Save in Vim
Vim Command | Description |
---|---|
|
Writes the file to disk |
Vim Save and Exit
How to save and exit Vim, personally I use :wq
Vim Command | Description |
---|---|
|
Save and exit Vim |
|
Exit - Vim will prompt and ask if you wish to save |
|
Another way to Save and Exit Vim |
|
Forces save on read only files, and exits |
Misc Vim Commands
Vim Undo Command
Vi Command | Description |
---|---|
|
Press |
Vim Undo All
Vim undo all since last write.
Vim Command | Description |
---|---|
|
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.