本文目录
A compact reference for everyday editing, using Vim’s default behavior.
Modes & notation
Commands start in Normal mode unless noted. <Esc> returns from Insert,
Replace, or Visual mode to Normal mode. : opens the command line.
<C-r>means Ctrl + r;<Enter>executes:,/, and?commands.[count]is optional;{char},{file}, and{text}are placeholders.- Type sequences directly:
ddpmeansddthenp. Arrows between steps are explanatory.
Move & jump
| Keys | Action |
|---|---|
h / j / k / l | Left / down / up / right |
w / W | Next word / WORD start |
b / B | Previous word / WORD start, or start of the current one |
e / E | Next word / WORD end (current one if before its end) |
0 / ^ / $ | Line start / first non-blank / line end |
f{char} / F{char} | Find character forward / backward on this line |
t{char} / T{char} | Move toward character forward / backward; stop one character short |
; / , | Repeat last f/F/t/T in the same / opposite direction |
% | Jump to the matching bracket: (), [], {} |
gg / G | First / last line of the file |
30G | Line 30 |
<C-o> / <C-i> | Older / newer position in the jump list |
<C-g> | Show file status and cursor position |
word vs WORD: a word separates keyword characters from punctuation;
a WORD is separated by whitespace. With default keyword rules, foo-bar is
three words but one WORD. See :help word for details.
% can also find a bracket at or after the cursor on the current line.
Combine movements: j$ goes to the end of the next line.
Operator + count + motion
[count]operator[count]motion — d deletes, c changes, y yanks (copies).
| Example | Action |
|---|---|
d2w / 2dw | Delete over two w movements |
2d3w | Delete over six w movements; counts multiply |
d$ / c$ / y$ | Delete / change / yank to line end |
3dd | Delete three lines, starting with this one |
Text objects select a region instead of moving to a destination:
| Object | Meaning | Examples |
|---|---|---|
iw | Inner word, without surrounding whitespace | diw, ciw, yiw |
aw | A word, including adjacent whitespace | daw, caw, yaw |
Use diw to delete a whole word from inside it; dw starts at the cursor.
Insert, delete & change
| Keys | Action |
|---|---|
i / a | Insert before / after the cursor |
I / A | Insert before the first non-blank / at line end |
o / O | Open a line below / above and enter Insert mode |
x / X | Delete the character under / before the cursor |
dw | Delete up to the next word start, excluding that start¹ |
de | Delete through the next word end, including that end |
d$ / D | Delete to line end |
dd | Delete the whole line |
ce | Delete through the next word end, then enter Insert mode |
c$ / C | Change to line end |
cc | Change the whole line |
r{char} | Replace the character under the cursor; stay in Normal mode |
R{text}<Esc> | Replace successive characters, then return to Normal mode |
All c commands enter Insert mode. On a non-blank character, cw behaves
like ce, leaving following whitespace alone.
¹ When the last word crossed by dw is at line end, deletion stops there.
de / ce reach the current word end if before it, or the next word end if already on it.
Select, copy & put
| Keys | Action |
|---|---|
v / V / <C-v> | Start character / line / block selection |
y / d / c in Visual mode | Yank / delete / change the selection |
yw | Yank up to the next word start; same line-end rule as dw |
yiw | Yank the whole word under the cursor |
yy | Yank the whole line |
p / P | Put characterwise text after / before the cursor |
p / P with whole lines | Put below / above the current line |
p/P put yanked or deleted text from a register (Vim’s text storage).
- Copy a selection:
v→ move to select →y→ move to destination →p. V4jy: select this line plus four below, then yank all five.ddp: move this line below the next one (when a next line exists).
Undo, redo & repeat
| Keys | Action |
|---|---|
u | Undo the last change |
U | Undo the latest changes on the last-modified line; itself undoable |
<C-r> | Redo an undone change |
. | Repeat the last change |
Search & options
| Keys | Action |
|---|---|
/pattern / ?pattern | Search forward / backward; press <Enter> |
n / N | Repeat the search in the same / opposite direction |
* / # | Search forward / backward for the whole word under the cursor |
/pattern\c / /pattern\C | Ignore / match case for this pattern, including repeats |
Search patterns are regular expressions, not necessarily literal text.
| Option or command | Short form | Effect |
|---|---|---|
:set ignorecase | :set ic | Ignore case |
:set noignorecase | :set noic | Match case |
:set hlsearch | :set hls | Highlight search matches |
:nohlsearch | :noh | Clear highlights until the next search |
:set nohlsearch | :set nohls | Disable search highlighting |
:set incsearch | :set is | Preview matches while typing |
Combine options: :set hls is. Pattern flags \c/\C override case options.
Substitute
:[range]s/pattern/replacement/[flags] — default range: current line.
| Command | Action |
|---|---|
:s/old/new/ | Replace the first match on this line |
:s/old/new/g | Replace every match on this line |
:10,20s/old/new/g | Replace every match on lines 10–20, inclusive |
:%s/old/new/g | Replace every match in the file |
:%s/old/new/gc | Replace across the file, confirming each match |
% means all lines; g means all matches per line; c asks for confirmation.
| Confirmation key | Action |
|---|---|
y / n | Replace / skip this match |
a | Replace this and all remaining matches |
q / <Esc> | Stop replacing |
l | Replace this match, then stop |
<C-e> / <C-y> | Scroll text up / down to inspect below / above |
Files & external commands
| Command | Action |
|---|---|
:e {file} | Open a file |
:w | Save the current file |
:w {file} | Write to another file; keep the current name if already named |
:saveas {file} | Save under a new name and use that name |
:q | Quit the current window; normally refuses unsaved changes |
:wq | Save and quit the current window |
:q! | Force quit the current window; discard changes if the buffer is closed |
:r {file} | Insert a file’s contents below the current line |
:!ls | Run the external shell command ls |
:r !ls | Insert the command’s output below the current line |
Help
| Command | Look up |
|---|---|
:help w | Normal-mode command w |
:help :w | Command-line command :w |
:help 'ignorecase' | An option |
In help: <C-]> follows a help tag, <C-o> goes back, and :q closes the help window.