What Is Vim?
Vim is a keyboard-driven text editor commonly used in terminals, remote servers, and development environments. Its defining idea is modal editing: the same keys perform different jobs depending on the current mode.
In Normal mode, keys move, delete, copy, and change text. Insert mode is for typing. Command-line mode handles actions such as saving, quitting, and search-and-replace. This may feel unusual at first, but it lets experienced users combine short commands without constantly reaching for a mouse.
When in doubt, press Esc once or twice to return to Normal mode.
Open Vim
Open a terminal or command prompt, then use the command that fits the task:
| Command | What it does |
|---|---|
vim | Open Vim with an empty buffer. |
vim notes.txt | Open an existing file or begin a new file with that name. |
vim file1 file2 | Open multiple files as separate buffers. |
vi notes.txt | Open the system's Vi editor. It may start Vim in a compatibility mode or use another Vi implementation. |
vim --version | Confirm Vim is installed and inspect its version and compiled features. |
vimtutor | Open Vim's interactive practice lesson when it is installed. |
Use vim when it is available so this guide's behaviour matches more closely. If the command is missing, install Vim through the operating system's normal package manager or official installer.
Understand the Main Modes
| Mode | Purpose | How to enter | How to leave |
|---|---|---|---|
| Normal | Navigate and run editing commands. | Vim starts here; press Esc from most other modes. | Use a key for another mode, such as i, v, or :. |
| Insert | Type ordinary text. | i, a, o, I, or A. | Esc |
| Visual | Select characters, lines, or blocks. | v, V, or Ctrl+v. | Esc |
| Command-line | Save, quit, configure, replace, and run longer commands. | :, /, or ? from Normal mode. | Press Enter to run or Esc to cancel. |
| Replace | Overwrite text as you type. | R | Esc |
Your First Edit from Start to Finish
- Open a practice file with
vim practice.txt. - Press
ito enter Insert mode. - Type two or three lines of text.
- Press
Escto return to Normal mode. - Type
:w, then pressEnterto save. - Type
:q, then pressEnterto quit.
If Vim reports unsaved changes, use :wq to save and quit or :q! only when those changes should be discarded.
Move Around in Normal Mode
| Key | Movement | Example use |
|---|---|---|
h / ← | One character left. | Correct the previous character. |
j / ↓ | One display line down. | Move to the line below. |
k / ↑ | One display line up. | Return to the line above. |
l / → | One character right. | Move toward the end of a line. |
w | Beginning of the next word. | 3w moves forward three words. |
b | Beginning of the previous word. | Jump back to edit an earlier word. |
e | End of the current or next word. | de deletes through a word ending. |
0 | First character of the line. | Return to column zero. |
^ | First non-blank character of the line. | Jump past indentation. |
$ | End of the line. | d$ deletes to the line end. |
gg | First line of the file. | Return to the top. |
G | Last line of the file. | Jump to the bottom. |
25G | Line 25. | Move to a known line number. |
f{char} / F{char} | Find a character to the right or left on the current line. | f: jumps onto the next colon. |
t{char} / T{char} | Move just before a character to the right or just after one to the left. | dt, deletes up to—but not including—the next comma. |
% | Jump to a matching bracket or another supported paired item. | Move between the opening and closing bracket around a block. |
Ctrl+d / Ctrl+u | Scroll about half a screen down or up. | Read a long file without making full-page jumps. |
Ctrl+f / Ctrl+b | Page forward or backward. | Move through a long file quickly. |
H / M / L | Move to the top, middle, or bottom line currently visible. | Reach a visible area without counting lines. |
Enter Text Efficiently
| Key | What it does | Example |
|---|---|---|
i | Insert before the cursor. | Place the cursor on a word and type at that position. |
a | Append after the cursor. | Add a character after the current one. |
I | Insert at the first non-blank character. | Add text before an indented line's content. |
A | Append at the end of the line. | Add a sentence ending or comment. |
o | Open a new line below and enter Insert mode. | Add the next item in a list. |
O | Open a new line above and enter Insert mode. | Insert a heading before the current line. |
R | Enter Replace mode. | Overwrite a run of existing characters. |
Esc | Return to Normal mode. | Finish typing before navigation or commands. |
Delete, Change, Copy, and Paste
| Command | Action | Example use |
|---|---|---|
r | Replace the character under the cursor. | Press rx to replace it with x. |
x | Delete the character under the cursor. | Remove one unwanted character. |
dd | Delete the current line. | 3dd deletes three lines. |
D | Delete from the cursor through the end of the line. | Remove the remainder of a sentence. |
dw | Delete from the cursor through a word motion. | Remove the next word-sized section. |
cw | Change a word motion and enter Insert mode. | Replace a word without a separate insert command. |
yy | Yank, or copy, the current line. | 2yy copies two lines. |
p | Put copied or deleted text after the cursor or below the line. | Copy a line with yy, move, then press p. |
P | Put text before the cursor or above the line. | Paste a copied line above the current one. |
u | Undo the latest change. | Reverse an accidental deletion. |
Ctrl+r | Redo an undone change. | Restore a change after pressing u. |
. | Repeat the last change. | Apply the same edit at another location. |
Understand Vim Registers
When Vim yanks or deletes text, it stores that text in a register. An ordinary p uses the unnamed register, while a double quote followed by a register name lets you choose a particular one.
| Example | What it does |
|---|---|
"0p | Put the most recently yanked text from register 0, even if a later deletion changed the unnamed register. |
"+y | After selecting text in Visual mode, yank it to the system clipboard register. In Normal mode, follow y with a motion, such as "+yw. |
"+p | Put text from the system clipboard into the file. |
The + register depends on Vim being built with clipboard support and having access to the desktop clipboard. Check :version when these commands do not work in a terminal or remote session.
The Operator-and-Motion Idea
Many Vim commands follow a small grammar: operator + motion. The operator says what to do, and the motion says how far.
| Operator | Meaning | Combined examples |
|---|---|---|
d | Delete. | dw, d$, dG |
c | Change, then enter Insert mode. | cw, c$ |
y | Yank, or copy. | yw, y$ |
Counts can come before an operator or motion: 3w moves three words, 2dd deletes two lines, and d3w deletes across three word motions. Learn the pieces instead of memorising every possible combination.
Select Text with Visual Mode
| Key | Selection | Typical next step |
|---|---|---|
v | Character-wise selection. | Move to expand, then press y, d, or c. |
V | Whole-line selection. | Select several lines for copying or indentation. |
Ctrl+v | Rectangular block selection. | Edit aligned columns of text. |
> / < | Indent or unindent the selection. | Adjust a selected code block. |
= | Reindent according to Vim's rules. | Use gg=G to reindent the whole file. |
Search and Replace
| Command | Purpose |
|---|---|
/text | Search forward for text. |
?text | Search backward for text. |
n / N | Repeat the search in the same or opposite direction. |
* | Search forward for the word under the cursor. |
:%s/old/new/g | Replace every old match with new on every line. |
:%s/old/new/gc | Perform the same replacement but ask for confirmation. |
Vim search patterns use a regex flavour with its own escaping rules. Preview a search with /pattern before using it in a file-wide replacement, and add the c flag when the change needs review.
Turn On Helpful Display Settings
Use :set commands to change the current Vim session:
:set number
:set relativenumber
number shows each line's actual number. relativenumber shows nearby lines by their distance from the cursor, which makes commands such as 5j or 3dd easier to plan. Use :set norelativenumber to turn the relative display off.
Save and Quit
| Command | Result |
|---|---|
:w | Write changes to the current file. |
:w new-name.txt | Write the current buffer's contents to another file. This does not necessarily change the filename associated with the current buffer. |
:saveas new-name.txt | Save under a new filename and make it the current buffer's filename. |
:q | Quit when there are no unsaved changes. |
:wq | Write changes and quit. |
:x | Write only when changed, then quit. |
ZZ | Normal-mode shortcut similar to :x. |
:q! | Quit and discard unsaved changes in the current buffer. |
Use :q! deliberately. The exclamation mark forces the action and discards changes that have not been saved elsewhere.
Work with Multiple Files
| Command | Purpose |
|---|---|
:e FILE | Edit another file in the current window. |
:ls | List open buffers. |
:bnext / :bprevious | Move between buffers. |
:buffer NUMBER | Open a listed buffer by number. |
:split FILE | Open a horizontal split. |
:vsplit FILE | Open a vertical split. |
Ctrl+w then h/j/k/l | Move between split windows. |
Keep Small Settings in .vimrc
Session settings disappear when Vim exits. Put deliberate defaults in your Vim startup file—commonly ~/.vimrc on Unix-like systems or _vimrc on Windows—so they are applied each time Vim starts:
set number
set ignorecase
set smartcase
set incsearch
This shows line numbers, ignores case for ordinary searches, restores case sensitivity when the search contains an uppercase letter, and displays matches while a search is being typed. Run :version to see the startup-file locations used by the installed Vim. Begin with a small configuration like this; plugins are not required to learn the editor.
Get Help Inside Vim
:help
:help dd
:help :w
:help pattern
Help topics are tied to the installed Vim version, which makes them especially useful for checking exact behaviour. Press Ctrl+] on a highlighted help tag to follow it and Ctrl+o to return.
Common Beginner Mistakes
- Typing commands while still in Insert mode. Press
Escfirst. - Forgetting that commands are case-sensitive:
iandIdo different things. - Pressing
:q!without realising it discards unsaved work. - Using arrow keys exclusively and never learning word, line, and file motions.
- Copying a configuration file full of plugins before learning core editing behaviour.
- Ignoring a swap-file warning without first checking whether another Vim session is editing the file or whether recovery is needed.
A Ten-Minute Practice Routine
- Open
vim practice.txtand type five short lines withi. - Use
w,b,0,$,gg, andGto navigate. - Copy one line with
yyand paste it withp. - Change a word with
cw, repeat the edit elsewhere with., then undo and redo it. - Search with
/textand move between results withn. - Save with
:w, make one disposable change, then leave with:q!.
Quick Recap
- Normal mode is for commands; Insert mode is for typing.
- Motions describe where to move, and operators describe what to do.
- Counts, operator-motion combinations, and the repeat command make edits efficient.
- Visual mode selects text, while Command-line mode handles saving, quitting, and replacements.
Esc,u,:w, and:q!are the essential recovery controls for a beginner.vimtutorand:helpare the best next steps after this page.
