What Is Vim?

Vim is a keyboard-driven text editor commonly used in terminals. It uses Normal mode for navigation and commands, Insert mode for typing, and Command-line mode for actions such as saving and quitting.

When in doubt, press Esc to return to Normal mode.

Opening Vim

Open a terminal or command prompt, then use one of these commands:

Command What It Does
vimOpen Vim with an empty buffer.
vim notes.txtOpen an existing file or create it when you save.
vi notes.txtOpen the system's Vi editor. On many systems this starts Vim, but it may use another Vi implementation.
vim --versionCheck whether Vim is installed and view its version.

Use vim when it is available so the behavior matches this guide. If the command is not found, install Vim through your operating system's package manager.

Essential Commands

Key/Command Description
iEnter Insert mode and type before the cursor.
aEnter Insert mode and type after the cursor.
EscLeave Insert mode and return to Normal mode.
j or Move the cursor down one line.
k or Move the cursor up one line.
h or Move the cursor left one character.
l or Move the cursor right one character.
IEnter Insert mode at the first non-blank character of the line.
AEnter Insert mode at the end of the line.
rReplace the character under the cursor.
bMove to the beginning of the previous word.
wMove to the beginning of the next word.
0 or $Move to the beginning or end of the current line.
gg or GMove to the first or last line of the file.
xDelete the character under the cursor.
ddDelete the current line.
DDelete from the cursor to the end of the line.
yyCopy the current line.
pPaste copied or deleted text after the cursor.
uUndo the last change.
Ctrl+rRedo the last undone change.
/textSearch forward for text.
nMove to the next search result.
:wSave the file.
:wqSave the file and quit Vim.
:q!Quit Vim and discard unsaved changes.

Practice Examples

Open a safe practice file with vim practice.txt, then add three short lines:

first line
second line
third line
  1. Insert and append: press i to type before the cursor or a to type after it, then press Esc.
  2. Navigate: use h, j, k, and l to move around the text.
  3. Copy and paste: place the cursor on a line, press yy, then press p.
  4. Delete: press dd to remove a line or D to remove everything after the cursor.
  5. Undo: press u to reverse the last change.
  6. Finish: use :w to save, :wq to save and quit, or :q! to discard the practice changes.