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 |
|---|---|
vim | Open Vim with an empty buffer. |
vim notes.txt | Open an existing file or create it when you save. |
vi notes.txt | Open the system's Vi editor. On many systems this starts Vim, but it may use another Vi implementation. |
vim --version | Check 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 |
|---|---|
i | Enter Insert mode and type before the cursor. |
a | Enter Insert mode and type after the cursor. |
Esc | Leave 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. |
I | Enter Insert mode at the first non-blank character of the line. |
A | Enter Insert mode at the end of the line. |
r | Replace the character under the cursor. |
b | Move to the beginning of the previous word. |
w | Move to the beginning of the next word. |
0 or $ | Move to the beginning or end of the current line. |
gg or G | Move to the first or last line of the file. |
x | Delete the character under the cursor. |
dd | Delete the current line. |
D | Delete from the cursor to the end of the line. |
yy | Copy the current line. |
p | Paste copied or deleted text after the cursor. |
u | Undo the last change. |
Ctrl+r | Redo the last undone change. |
/text | Search forward for text. |
n | Move to the next search result. |
:w | Save the file. |
:wq | Save 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
- Insert and append: press
ito type before the cursor orato type after it, then pressEsc. - Navigate: use
h,j,k, andlto move around the text. - Copy and paste: place the cursor on a line, press
yy, then pressp. - Delete: press
ddto remove a line orDto remove everything after the cursor. - Undo: press
uto reverse the last change. - Finish: use
:wto save,:wqto save and quit, or:q!to discard the practice changes.
