Best Vim Cheat Sheet

Vim Cheat Sheet Outline

  1. Vim Cheat Sheet For Programmer
  2. Best Vim Cheat Sheet 2019
  3. Best Vim Cheat Sheets
  4. Best Vim Cheat Sheet 2020

For Those Just Getting Started

Quick Start/Cheat Sheet. Vim commands are more of a language than a list of commands you need to use. From the Command Line. Type “vim” into the command line to create a new untitled file; type “vim /path/to/” to open an existing file. (if the file doesn’t exist, this creates it).


  • Maybe it's because you haven't done:h change.txt.Also check out:h motion.txt.In fact, just:h and scrolling through, skimming, and ducking in and out of the sections is super rewarding. I don't think there's anything Vim can do that you can't find by reading through the helps.
  • Vim Cheat Sheet. My collection of vim tips to make the best editor even better. This is by no means complete or a tutorial on how to use vim, but a set of commands I don't want to forget and need to write them down before they burn into memory. See the resources section below for a more complete introduction and a set of in-depth tutorials.
  • L - move to bottom of screen. W - jump forwards to the start of a word. W - jump forwards to the start of a word (words can contain punctuation) e - jump forwards to the end of a word. E - jump forwards to the end of a word (words can contain punctuation) b - jump backwards to the start of a word.
  • This is the default mode in which Vim starts up. Insert mode is the mode where you insert/write your text. Visual mode is where you visually select a bunch of text so that you can run a command/operation only on that part of the text. Basic Vim Commands. Let’s start with an easy set of Vim commands to open, save, and exit Vim.

The goal with these seven sections is to give the beginner confidence to replace existing tools with the Vim editor.

  1. Vim Modes - Navigating modes
  2. Vim Command Structure - Counts, Operators and Motions
  3. Vim Editing - Undo, replace, delete and append
  4. Vim Cut, Copy and Paste - Edit in Visual and Normal Modes
  5. Vim Search and Replace - Edit in Normal and Command Modes
  6. Vim Command Mode - Save, quit, write, read
  7. Vim Registers - Reuse saved blocks of text
  8. Vim Tabs - Manage multiple files in tabs

Accepting that Vim has over 1,000 commands, we only had space to cover about 80 essential commands, but these should provide a good base of knowledge to launch a further exploration of Vim commands.

Vim and Vi Version Confusion

On most modern Linux distributions for command-line operation, Vim is the replacement for the Vi editor, despite being launched with the command vi. If this is the case for you, your system is most-likely running a limited version of Vim, called vim-tiny. You can find your version using :ve inside Vim. If it says 'Small version without GUI' then you have a limited, but small program. Many of the commands covered in this Vim cheat sheet will not work for you as vim-tiny emulates vi commands and vi shortcuts, so keep that in mind.

If that is the case for you, and you can upgrade to the full version of Vim, called vim-runtime, look for a tutorial on this later.

Vim Modes

Keystrokes have alternative meanings in each mode. So a vital first step is knowing your current mode and how to navigate between them.

  • Normal Mode - navigating and some editing
  • Insert Mode - editing and appending text
  • Visual Mode - selecting and moving text
  • Command Mode (Ex Mode) - entering Vim commands

The default or home mode is Normal Mode and Esc returns you here.

Navigating Vim Modes

Keystrokes used to navigate between Vim modes.

Current ModeDesired ModeCharacter(s)
Normal ModeInsert ModeA, a, C, I, i, O, o, S, s
Normal ModeCommand Mode (Ex Mode):
Normal ModeVisual Modev
Any ModeNormal ModeEsc (sometimes twice)
Best Vim Cheat Sheet

So if you make unintended keystrokes, return to Normal Mode using Esc. There are other ways to navigate between modes of course, and here we cover the basics for beginners.

Vim Command Structure

Counts, Operators and Motions

A combined command is one that can be applied multiple times, taking a variety of actions in all directions.

  • Counts - The number of times to repeat an Operator or Motion, often abbreviated as N
  • Operators - Actions or Vim commands to perform
  • Motions - A navigational direction to move the cursor

Below is a short example of three combined commands translated into Counts, Operators and Motions.

Combined commandCountOperatorMotionWhat does it do?
5dw5dwDelete 5 words
3j3jMove down 3 lines
3g~l3g~lSwap case for next 3 characters

All Counts 1, 2, 3, 4, 5, 6, 7, 8, 9 require an Operator and/or Motion afterwards. Use Esc to erase an unwanted Count. Counts are optional, and without a Count you can think of the default being 1.

0 is not a Count, but instead moves the cursor to the first column of a line.


Of the 15 Operators in total, below are those commonly used by beginners. Operators are optional.

g~Swap case
guMake lowercase
gUMake uppercase
yYank (copy)
<Shift left
>Shift right

Vim Motions can optionally be preceded by a Count and/or an Operator. Vim will move or take action from the cursor a specified number of times and remain in Normal Mode. Also note, there are many ways (over 90) to initiate a Motion but to save time and to avoid feeling overwhelmed, start with those in the first column.

hBackspace, Ctrl-hLeftCharacters
jEnter, Ctrl-j, Ctrl-m, Ctrl-nDownLines
Ctrl-dDown1/2 Screens
Ctrl-uUp1/2 Screens

The Ctrl-s keystroke is used for Linux Terminal control and may lock your Vim console. If this happens, hit Ctrl-q to regain control.

Other Motions

The following are important and commonly-used Motions.

CharacterPrefix with Count?Motion
0 (zero)NoMove cursor to beginning of current line
$YesMove cursor to end of current line
^NoMove cursor to first non-blank character of current line
g_YesMove cursor to last non-blank character of current line
ggNoGo to start of file
GNoGo to end of file
HNoGo to top of screen
LNoGo to bottom of screen
MNoGo to middle of screen
zzNoCenter the screen around the cursor

A Count plus the vertical bar or pipe will go to that column of the current line. So 80 will go to column 80.

Vim Editing

Two Modes for Editing: Normal Mode and Insert Mode

Here we cover editing files from two modes. Light edits are performed while remaining in the default Normal Mode, while others such as appending text take a Motion followed by a change to Insert Mode.

Normal Mode Vim Editing
CharacterPrefix with Count?Meaning
uYesUndo the last edit
Crtl-rYesRedo last undo changes
rYesReplace one or several characters
xYesDelete character under cursor and forward
.YesRepeat the last change at the cursor

The r command is recommended for beginers over R which kicks you into a whole different mode called Replace Mode. It is often easier to use Insert Mode to edit larger blocks of text, rather than learn a new mode.

Insert Mode Vim Editing
CharacterPrefix with Count?Meaning
aYesAppend text after cursor position
AYesAppend text at end of line
CYesCut text from cursor to end of line
IYesInsert text at the first non-blank character of the line
iYesInsert text before the cursor
OYesOpen line(s) above cursor
oYesOpen line(s) below cursur
SYesSwap or delete line(s) for newly created line
sYesSwap or delete character(s) for newly type characters

Vim Cut, Copy and Paste

Two Modes: Visual Mode and Normal Mode

Here are two ways to select blocks of text to accomplish standard cut, copy and paste operations. First, and easiest for those coming from other visual editors, is in Visual Mode. Second is remaining in Normal Mode.

Visual Mode

The following keystrokes perform the most basic copy and paste, switching from Normal Mode to Visual Mode.

vSwitch to Visual Mode for character selection
yYank (copy) text selected with Motions
pPut (paste) selected text block after the cursor
xdDelete a block of selected text
Ctrl-v, (select rows), Shift+i, (add text), EscThis enters Visual Block mode and is helpful for adding text or comment characters in front of multiple lines.

Once you enter Visual Mode text is highlighted as you select blocks of text with standard Motions. After you are happy with the block, type your cut or copy command from the table above. You will then automatically return to Normal Mode to paste the text.

Many find Visual Mode easier to grasp at first but advancing to Normal Mode for cut, copy and paste operations can save keystrokes.

The Visual Block Mode example above can be a timesaver if for example you wanted to comment out 20 lines of code in Python with the hash # character. Start at the first line where you want to enter a comment and hit Ctrl+v, then navigate down the 19 lines, hit Shift+i and input the text you would like, here a # and space, then Esc.

Normal Mode

To perform cut, copy and paste operations from within Normal Mode requires a good understanding of Motions.

CharacterPrefix with Count?Meaning
y$YesYank (copy) to end of line
yyYesYank (copy) the whole current line
ywYesYank (copy) current word
YYesYank (copy) the whole current line
PYesPut (paste) before the cursor
pYesPut (paste) after the cursor

Vim Search and Replace

Search Lines, Files and Replace Text

Vim offers many commands to search for and replace text at the line-level and file-level.

We will stick with the basics here, but at a more advanced level, with regular expressions, the Vim editor offers the ability initiate any search imaginable, even across whole filesystems.

Search Lines

Searching for characters within lines can be helpful for jumping to specific coding symbols and letters.

CharacterPrefix with Count?Meaning
f{character}YesSearch current line right for N occurance of {character}
F{character}YesSearch current line left for N occurance of {character}
Search Files

File-level search is one of the most common functions for Vim users, and most users memorize one of the two pattern recognition commands because when combined with the n and N symbols noted above, they both can direct Vim to search up and down a file just as easily, so using / or ? is your preference.

CharacterPrefix with Count?Meaning
/{pattern}ReturnYesSearch for next N occurance of {pattern}
?{pattern}ReturnYesSearch for previous N occurance of {pattern}
nYesSearch for next N occurance of an already initiated search in the same direction
NYesSearch for next N occurance of an already initiated search in the opposite direction
:noh<Enter>NoTo turn off highlighting of searched-for text.
Search and Replace

Here we start to see entries in Command Mode using the : character. The term Command Mode, often confuses beginners because you can enter Vim commands from any mode. Official Vim documentation refers to commands entered with : as Ex Commands, but most people use the term Command Mode.

:%s/{search}/{replace}/gcSearch over the range (% for whole file) for all occurances of {search} and replace with {replace}.
:10,20s/{search}/{replace}/gcSearch over the range (lines 10 to 20) for all occurances of {search} and replace with {replace}.

The only spaces allowed in the string above sit between the / characters, and the { and } characters are not typed. The g means globally over the whole file and c instructs Vim to provide a confirmation before each replacement is made.

A confirmation dialog will prompt you for one of seven choices.

  1. y - substitute at current stop
  2. n - skip this substitution
  3. a - accept all future substitutions
  4. q - quit the search and replace
  5. l - substitute at current stop then quit
  6. ^E (Ctrl-e) - scroll up to previous stop
  7. ^Y (Ctrl-y) - scroll down to next stop

If you leave the c off the end of the command, Vim will perform all replacements in the whole file almost instantly, so it is best for beginners to start with confirming changes.

A Search and Replace Example

The following command uses Regular Expressions to remove the last one or several blank spaces at the end of each line in a file :%s/s+$//.

Vim Command Mode

Save, Quit, Write and Read

Many essential commands sit in Command Mode, sometimes called Ex Command Mode. All of the following commands are input from Normal Mode, so from any other mode, hit Esc once (sometimes twice) to return to Normal Mode. When entering Command Mode, once the colon character : is pressed, your additional keystrokes appear at the bottom left of the screen.

There are as many as 515 commands in Command Mode and many can be abbreviated. Also, unlike with other modes, commands here, because they are open-ended, require Enter to complete.

:w:writeWrite (save) current and previously-named file.
:w {file}:write {file}Write (save) current file and name it {file}.
:wq:x, ZZWrite (save) current and previously-named file and quit Vim.
:q:quitQuit Vim from an unedited file.
:q!ZQQuit Vim from an edited or unedited file without saving changes.
:e {file}:edit {file}Edit a file named {file}.
:r {file}:read {file}Read an external file named {file} at the current cursor position.
:sh:shellTo leave Vim temporarily and go to the shell. Type exit to return.
:!{cmd}To run a shell command {cmd}. Hit q to return to Vim.
:h:helpOpen help in a new window. Use :q to quit help.

Vim Registers

Vim Registers allow you to save blocks of code to paste anywhere you like. Functionality is much like cut, copy and paste operations elsewhere but Registers allow you to save many blocks, using letters a-z and A-Z, so you have 52 slots. The last 10 yanks and deletes are automatically saved under the 0-9 slots in the Register. These can be viewed with :reg.

Creating, pasting and deleting Registers

Registers work logically with actions in Normal Mode and Visual Mode. The ' symbol starts the Register functionality. Examples below use the empty Register name c.

'cyyTo save a Register from Normal Mode under the name c of a whole line.
'cyTo save a Register from Visual Mode under the name c of a selected section.
'cpTo put (paste) text from the saved Register named c while in Normal Mode.
:call setreg('c', [])To delete an item from the Register replace it with empty text.
:reg:registersView the currently saved Registers. Type q to quit.
:h reg:help registersFind help on Registers. Type :q to quit.

Besides assigning Registers to letters and numbers, an additional 8 types exist for more advanced uses. These are described in help.

Vim Tabs

You can manage multiple text files in tabs within one Vim window. To navigate between tabs click tab titles with the mouse or use the keystrokes described below. The 'X' at the top right when clicked will close that tab.

To open a new blank tab.
:tabe {file}:tabedit {file}
:tabenew {file}
To open a new tab to edit {file}.
To close the current tab.
{count} gtTo specify which tab with {count} or go to the next tab. This wraps around forward.
{count} gTTo specify which tab with {count} or go to the previous tab. This wraps around backward.
:tabsList the current Vim tabs.

Additional Vim tab functionality includes reordering tabs, looping over tabs and closing all tabs. See :help tabs for more.

Related Content

  • A similarly organized Linux Cheat Sheet
  • Practice hjkl navigation with the Vimazing Race Maze Game
  • Common Vim commands with videos in the Vim Reference
Updated on July 13, 2020

Vim was made available in 1991 and is a free, open source software. Available both as a command line interface and as a standalone program with a GUI, Vim is a text editor that is a modal version of the vi editor created for Unix in the 1970s; Vim stands for vi improved. While it was designed with Unix in mind, versions of it are available for most operating systems and Vim is also available for Android and iOS smartphones.

While you may be familiar with the concept of a text editor, the modal part may throw you. A modal editor is one that allows you to edit text in different modes, and in the case of Vim, the mode determines what the alphanumeric keys on your keyboard do and how Vim editor commands work.

For example, in insert mode, your keyboard behaves normally, so what you type in is what you see, just like with a standard text editor. However, if you switch to command mode, the letters on your keyboard will allow you use Vim commands to move within the text. If you play video games that use the left-hand keys on the keyboard to move your character around, this concept is probably familiar to you.

To open a file using Vim you can use the following command (simply replace filename.css with your actual file name).

The idea behind having a modal text editor is that it allows you to write and edit text, including code, without requiring your hands leave the keyboard. Vim isn't for everyone, and it requires you to learn a variety of Vim editor commands to get the most out of it. That said, many people who have started using it and become comfortable with it won't even consider another editor. The image below shows an exampe of what a css file looks like when viewed using Vim.

This text editor is particularly well-suited for people who are programmers, coders, system administrators or individuals looking for a streamlined way to edit text. The editor allows you to edit text in multiple windows, which can be helpful to programmers and editors alike. If you're interested in giving Vim a shot, the following is a basic explanation of Vim modes and a list of frequently used Vim commands, along with a definition of what they do.

Vim modes

There are some arguments as to how many modes that Vim has, but the modes you're most likely to use are command mode and insert mode. These modes will allow you to do just about anything you need, including creating your document, saving your document and doing advanced editing, including taking advantage of search and replace functions.

Command mode

This is the default mode that you'll be in once you open Vim. If you're in a different mode and want to go back to command mode, just hit the Escape key. This mode allows you to use Vim commands and move through your document. From command mode, you can also use last-line commands, which generally start with the use of a colon. For example, :w saves your file and :q allows you to exit Vim.

Insert mode

This mode allows you to enter text into your document. You can enter insert mode by pressing the i key. Keep in mind that to save your document, you'll need to go back to command mode since only text input is allowed in this mode.

Installing Vim

There are a few ways to install Vim and the one you end up using will sometimes depend on which system you're using.

Install Vim using Git:

According to Vim themselves, install Vim via Git is the simplest and most efficient method. Simply use the following commands:

If you already have Vim installed but want to update to the latest version, you may need to use additional Git commands which can be found here.

Install Vim on Ubuntu/Debian:

If you're using Ubuntu or Debian use apt-get to install Vim, like so:

Install Vim on CentOS/Fedora:

If you're using CentOS or Fedora, use yum to install Vim:

If you want a more advanced set of features on CentOS/Fedora, you'll need to install vim-enhanced, to do this, run the following command instead:

Vim commands

The following is a list of frequently used commands and what they do. Many of the commands can be made to repeat by adding a number to the command. This is not an exhaustive list because more advanced commands, such as how to use multiple buffers, are not included. However, just about all of the basic commands for opening, editing and saving documents are included as well as commands that enable you to find and replace text and work with multiple documents.

1. Basic Vim commands

The most simple commands allow you to open and close documents as well as saving them. As with most other text editors, there are protections in place to help you avoid exiting the editor without having saved what you're working on.

:help [keyword] - Performs a search of help documentation for whatever keyword you enter

:e [file] - Opens a file, where [file] is the name of the file you want opened

:w - Saves the file you are working on

:w [filename] - Allows you to save your file with the name you've defined

:wq - Save your file and close Vim

:q! - Quit without first saving the file you were working on

2. Vim commands for movement

When using movement commands, you can put a number in front of them to make Vim complete a command multiple times. For example, 5h will move your cursor five spaces to the left, and 90j will put your cursor at the beginning of the 90th line down from where your cursor currently is.

h - Moves the cursor to the left

l - Moves the cursor to the right

j - Moves the cursor down one line

k - Moves the cursor up one line

H - Puts the cursor at the top of the screen

M - Puts the cursor in the middle of the screen

L - Puts the cursor at the bottom of the screen

w - Puts the cursor at the start of the next word

b - Puts the cursor at the start of the previous word

e - Puts the cursor at the end of a word

0 - Places the cursor at the beginning of a line

$ - Places the cursor at the end of a line

) - Takes you to the start of the next sentence

( - Takes you to the start of the previous sentence

Vim Cheat Sheet For Programmer

} - Takes you to the start of the next paragraph or block of text

{ - Takes you to the start of the previous paragraph or block of text

Ctrl + f - Takes you one page forward

Ctrl + b - Takes you one page back

gg - Places the cursor at the start of the file

Best Vim Cheat Sheet

G - Places the cursor at the end of the file

# - Where # is the number of a line, this command takes you to the line specified

3. Vim commands for editing

Those who use Vim tend to use the term 'yank' where most people would use the terms copy and paste. Therefore, the command for copying a word is yw, which stands for yank word, and the command for pasting whatever has been copied is p, meaning put. If you look up additional commands in the future, it can be confusing if you don't know what yank and put mean when using Vim.

You also have two options for how to select text. You can either use commands like dd, which deletes a single line, and yy, which copies a single line, or you can highlight text and then copy it to the unnamed register. The paste commands work the same whether you've highlighted text or used a command to automatically copy it.

As with movement commands, putting a number in front of the command can increase the number of times a task is completed. For instance, putting a number in front of yy will increase the number of lines copied, so 5yy will copy five lines.

yy - Copies a line

yw - Copies a word

y$ - Copies from where your cursor is to the end of a line

v - Highlight one character at a time using arrow buttons or the h, k, j, l buttons

Macromedia flash player update. V - Highlights one line, and movement keys can allow you to highlight additional lines

p - Paste whatever has been copied to the unnamed register

d - Deletes highlighted text

dd - Deletes a line of text

dw - Deletes a word

D - Deletes everything from where your cursor is to the end of the line

d0 - Deletes everything from where your cursor is to the beginning of the line

dgg - Deletes everything from where your cursor is to the beginning of the file

dG - Deletes everything from where your cursor is to the end of the file

x - Deletes a single character

u - Undo the last operation; u# allows you to undo multiple actions

Ctrl + r - Redo the last undo

. - Repeats the last action

4. Vim commands for searching text

Like many other text editors, Vim allows you to search your text and find and replace text within your document. If you opt to replace multiple instances of the same keyword or phrase, you can set Vim up to require or not require you to confirm each replacement depending on how you put in the command.

/[keyword] - Searches for text in the document where keyword is whatever keyword, phrase or string of characters you're looking for

?[keyword] - Searches previous text for your keyword, phrase or character string

n - Searches your text again in whatever direction your last search was

N - Searches your text again in the opposite direction

:%s/[pattern]/[replacement]/g - This replaces all occurrences of a pattern without confirming each one

:%s/[pattern]/[replacement]/gc - Replaces all occurrences of a pattern and confirms each one

5. Vim commands for working with multiple files

You can also edit more than one text file at a time. Vim gives you the ability to either split your screen to show more than one file at a time or you can switch back and forth between documents. As with other functions, commands make going between documents or buffers, as they're referred to with Vim, as simple as a few keystrokes.

:bn - Switch to next buffer

:bp - Switch to previous buffer

:bd - Close a buffer

:sp [filename] - Opens a new file and splits your screen horizontally to show more than one buffer

:vsp [filename] - Opens a new file and splits your screen vertically to show more than one buffer

:ls - Lists all open buffers

Ctrl + ws - Split windows horizontally

Ctrl + wv - Split windows vertically

Ctrl + ww - Switch between windows

Ctrl + wq - Quit a window

Ctrl + wh - Moves your cursor to the window to the left

Ctrl + wl - Moves your cursor to the window to the right

Ctrl + wj - Moves your cursor to the window below the one you're in

Ctrl + wk - Moves your cursor to the window above the one you're in

6. Marking text (visual mode)

Visual mode allows you to select a block of text in Vim. Once a block of text is selected you can use visual commands to perform actions on the selected text such as deleting it, copying it, etc.

v - starts visual mode, you can then select a range of text, and run a command

V - starts linewise visual mode (selects entire lines)

Ctrl + v - starts visual block mode (selects columns)

ab - a block with ()

aB - a block with {}

ib - inner block with ()

iB - inner block with {}

aw - mark a word

Best Vim Cheat Sheet 2019

Esc - exit visual mode

Once you've selected a particular range of text, you can then run a command on that text such as the following:

d - delete marked text

y - yank (copy) marked text

> - shift text right

< - shift text left

~ - swap case (upper or lower)

7. Tab pages

Just like any browser, you can also use tabs within Vim. This makes it incredibly easy to switch between multiple files while you're making some code changes instead of working in one single file, closing it, and opening a new one. Below are some useful Vim commands for using tab pages:

:tabedit file - opens a new tab and will take you to edit 'file'

gt - move to the next tab

gT - move to the previous tab

#gt - move to a specific tab number (e.g. 2gt takes you to the second tab)

:tabs - list all open tabs

:tabclose - close a single tab

Simple Vim workflow example

Best Vim Cheat Sheets

If you haven't had a chance to play around with Vim much yet, you might be wondering what a simple workflow looks like when using it. It's relatively simple:

  1. Open a new or existing file with vim filename.
  2. Type i to switch into insert mode so that you can start editing the file.
  3. Enter or modify the text with your file.
  4. Once you're done, press the escape key Esc to get out of insert mode and back to command mode.
  5. Type :wq to save and exit your file.

Best Vim Cheat Sheet 2020

Of course, there is so much more you can do with Vim, however as a beginner, the above steps are what a simple Vim workflow looks like.


Vim is quite easy to use, it just involves memorizing Vim editor commands and remembering what mode you're in. If you're used to using keyboard shortcuts like Ctrl + C and Ctrl + S, you shouldn't have too much difficulty getting used to the way that Vim works. While there is a bit of a breaking in period with the editor, you don't have to worry too much about accidentally deleting large swathes of text without being able to recover them since you can use the undo command multiple times.

While not for everyone, functionality like being able to work on more than one document at a time in windowed screens and the ability to do major editing without a mouse is what makes Vim so popular. You can download the editor for free, and there are a variety of plugins and extensions that can improve its functionality and add additional Vim commands.