Vim Commands Cheat Sheet

Vim is a widely used, open-source Unix text editor. Learning to use Vim commands is a matter of practice and experience. That is why it is handy to have a helpful reference sheet while mastering them.

In this tutorial, you will find the most important Vim commands as well as a downloadable cheat sheet.

Vim commands: Cheat Sheet.

Moving Inside a File

You can move the cursor within a file by single characters, words, tokens, or lines.

According to Vim, a word can be a group of letters, numbers, and underscores. On the other hand, a token is anything separated by whitespace and can include punctuation.

Additionally, you can move to different parts of a text by screen view.

Moving by Characters, Words and Tokens

The basic keys for moving the cursor by one character are:

You can also use these keys with a number as a prefix to move in a specified direction multiple times. For example, if you run 5j the cursor moves down 5 lines.

For instance, you have the noun phrase “step-by-step” as part of a text and the cursor is placed at the end of it. The first time you press b , the cursor moves back to “step-by-step”. However, if you use B , the cursor moves all the way back to: “step-by-step” since there is no whitespace between these characters.

Moving by Lines

To illustrate the difference between 0 and ^ , take a look at the following example. In the first bullet, the command moves the cursor to the blank space before the bullet. On the other hand, in the third bullet, the ^ key moves the cursor to the hyphen (the first character in the line).

Move the the beginning of line in Vim.

Note: To use the #G / #gg to jump to the wanted line, line numbering needs to be enabled. Check out how to show or hide line numbers in Vim/Vi.

To learn more about matchpairs and how to use more than the default supported pairs, run the following commands in the text editor: :h matchpairs .

Commands for finding matchpairs in Vim.

Moving by Screens

The following commands are used as a quick way to move within the text without scrolling.

Inserting Text

Some of these commands switch between command and insert mode. By default, Vim launches in command mode, allowing you to move around and edit the file. To switch to command mode, use the Esc key.

On the other hand, the insert mode enables you to type and add text into the file. To move to insert mode, press i .

Switch to insert mode.

Editing Text

Note: Bear in mind that Vim undoes and redoes changes by entries (changes made within one insert mode session). For more details, refer to the article How to Undo and Redo Changes in Vim.

Cutting, Copying And Pasting

Note: Find more commands and options in How to Cut, Copy, and Paste in Vim/Vi.

Marking Text (Visual Mode)

Apart from command mode and insert mode, Vim also includes visual mode. This mode is mainly used for marking text.

Based on the chunk of text you want to select, you can choose between three versions of visual mode: character mode, line mode, and block mode.

Once you have enabled one of the modes, use the navigation keys to select the desired text.

Versions of visual mode in Vim.

Visual Commands

Once you have selected the desired text in visual mode, you can use one of the visual commands to manipulate it. Some of them include:

Search in File

Note: Searching in Vim/Vi is a task you will certainly perform often. Get to know all the search options in How To Search To Find A Word In Vim Or Vi Text Editor. To keep track of all the changes Vim shows how to use find and replace function.

Saving and Exiting File

Note: Learn more about how to exit using Vim commands or shortcut keys with How To Exit (Quit) Linux Vim/Vi Editor.

Working with Multiple Files

List all buffers in Vim.

Open files as tabs in Vim.

Marks and Jumps

Macros

Enabling Vim Color Schemes

The list of Vim color schemes shows you the ones that come by default with the text editor, as in the image below:

List Vim color schemes.

You can also configure the color settings manually or download user-made schemes. Find out how to do so in How to Change and Use Vim Color Schemes.

Vim Commands Cheat Sheet

This article includes a one-page Vim commands reference sheet. Save the cheat sheet in PDF format by clicking the Download Cheat Sheet button below.

Vim commands cheat sheet PDF preview

Knowing basic Vim commands is useful as most Linux distributions have it installed by default. Once you get use to using Vim commands, mastering Vim should be simple.

Until then, keep a Vim cheat sheet at hand.