Vim Commands
Vim cheat sheet — modes, movement, editing, search & replace, files, windows, marks, and macros. Every command you reach for in daily editing.
A quick-reference for the Vim commands developers use daily. Organized by what you're trying to do, not by alphabet.
No matches.
Vim has hundreds of commands but you only need a couple of dozen to be productive. The tables below are organized by task. Press Esc to return to normal mode if you're ever lost. :help <command> opens the manual entry for any command.
Modes
Vim is modal — what a key does depends on which mode you're in.
| Command | Description |
|---|---|
Esc | Return to Normal mode (the default). |
i | Enter Insert mode at the cursor. |
I | Enter Insert mode before the first non-blank character of the line. |
a | Enter Insert mode after the cursor (append). |
A | Enter Insert mode at the end of the line. |
o | Open a new line below the cursor and enter Insert mode. |
O | Open a new line above the cursor and enter Insert mode. |
v | Enter Visual mode (character-wise selection). |
V | Enter Visual Line mode (whole-line selection). |
Ctrl-v | Enter Visual Block mode (rectangular selection). |
: | Enter Command-line mode for ex commands like :w, :q, :s/. |
R | Enter Replace mode (overwrites characters as you type). |
Movement
Most movements can be prefixed with a count: <code>5j</code> moves down 5 lines.
| Command | Description |
|---|---|
h / j / k / l | Left / down / up / right by one character or line. |
w / W | Move forward to next word start. W treats only whitespace as a separator. |
b / B | Move backward to previous word start. |
e / E | Move forward to end of current/next word. |
0 | Move to start of line (column 0). |
^ | Move to first non-blank character of the line. |
$ | Move to end of line. |
gg | Go to first line of the file. |
G | Go to last line of the file. <count>G goes to that line. |
Ctrl-d / Ctrl-u | Half-page down / up. |
Ctrl-f / Ctrl-b | Full-page down / up. |
{ / } | Jump backward / forward by paragraph. |
% | Jump to matching bracket / paren / brace. |
* | Search forward for the word under the cursor. |
# | Search backward for the word under the cursor. |
f<char> | Move forward to the next <char> on this line. |
F<char> | Move backward to the previous <char> on this line. |
t<char> / T<char> | Move "till" the next/previous <char> (one before it). |
; | Repeat the last f / F / t / T motion. |
, | Repeat the last f / F / t / T motion in reverse. |
H / M / L | Top / middle / bottom of the visible window. |
zz | Center the cursor line on the screen. |
Editing
Most editing commands are <code><operator><motion></code>, e.g. <code>d3w</code> = delete 3 words, <code>cit</code> = change inside HTML tag.
| Command | Description |
|---|---|
x | Delete the character under the cursor. |
X | Delete the character before the cursor (backspace). |
dd | Delete the current line. |
D | Delete from cursor to end of line. |
d<motion> | Delete from cursor through <motion>. Examples: dw, d$, dG. |
cc | Change the current line (delete and enter Insert mode). |
C | Change from cursor to end of line. |
c<motion> | Change from cursor through <motion>. |
s | Substitute character — delete one char, enter Insert mode. |
S | Substitute line — like cc. |
r<char> | Replace the character under the cursor with <char>. |
yy | Yank (copy) the current line. |
Y | Yank the current line (same as yy) in Vim. Neovim maps Y to y$ (yank to end of line). |
y<motion> | Yank from cursor through <motion>. |
p / P | Paste after / before the cursor. |
u | Undo. |
Ctrl-r | Redo. |
. | Repeat the last change. |
>> | Indent the current line. Visual: > / <. |
<< | Outdent the current line. |
~ | Toggle case of the character under the cursor. |
J | Join the current line with the next. |
gu<motion> | Lowercase through <motion>. |
gU<motion> | Uppercase through <motion>. |
Text Objects
Text objects pair with operators (<code>d</code>, <code>c</code>, <code>y</code>, <code>v</code>) to act on a structural unit. <code>i</code> = inside, <code>a</code> = around (includes delimiters).
| Command | Description |
|---|---|
iw / aw | Inside / around word. |
is / as | Inside / around sentence. |
ip / ap | Inside / around paragraph. |
i" / a" | Inside / around double quotes. |
i' / a' | Inside / around single quotes. |
i( / a( (also i) / a) ) | Inside / around parentheses. |
i[ / a[ | Inside / around square brackets. |
i{ / a{ (also iB / aB) | Inside / around curly braces. |
it / at | Inside / around HTML/XML tag. |
Search & Replace
| Command | Description |
|---|---|
/pattern | Search forward for pattern. |
?pattern | Search backward for pattern. |
n / N | Repeat search in the same / opposite direction as the last search. |
:s/foo/bar/ | Replace first occurrence of foo with bar on the current line. |
:s/foo/bar/g | Replace all occurrences on the current line. |
:%s/foo/bar/g | Replace every occurrence in the file. |
:%s/foo/bar/gc | Replace every occurrence with confirmation per match. |
:%s/foo/bar/gi | Case-insensitive replace. |
:noh | Clear search highlighting. |
Files & Buffers
| Command | Description |
|---|---|
:e <file> | Edit (open) a file. |
:w | Write (save) the current file. |
:w <file> | Write to a different file. |
:wa | Write all modified buffers. |
:q | Quit. |
:q! | Quit without saving. |
:wq / :x / ZZ | Write and quit; :x and ZZ write only when modified, while :wq writes regardless. |
:qa / :qa! | Quit all / quit all without saving. |
:ls / :buffers | List open buffers. |
:b <num/name> | Switch to a buffer. |
:bd | Delete (close) the current buffer. |
:bn / :bp | Next / previous buffer. |
Windows & Tabs
| Command | Description |
|---|---|
:sp <file> | Open file in a horizontal split. |
:vsp <file> | Open file in a vertical split. |
Ctrl-w h/j/k/l | Move between window splits. |
Ctrl-w w | Cycle to the next window. |
Ctrl-w c / :close | Close the current window. |
Ctrl-w o / :only | Close every window except the current one. |
Ctrl-w = | Equalize split sizes. |
:tabnew <file> | Open a new tab. |
gt / gT | Next / previous tab. |
:tabclose | Close the current tab. |
Marks & Registers
| Command | Description |
|---|---|
m<a-z> | Set mark — e.g. ma marks current position as a. |
'a | Jump to the line of mark a. |
`a | Jump to the exact position of mark a. |
'' | Jump back to the previous position before the last jump. |
:marks | List all marks. |
"<reg>y / "<reg>p | Yank to / paste from register, e.g. "ay yanks to register a. |
"+y / "+p | Yank to / paste from system clipboard. |
"0p | Paste the most recent yank (skips deletes). |
Macros
| Command | Description |
|---|---|
q<a-z> | Start recording a macro into register <a-z>. |
q | Stop recording. |
@<a-z> | Replay the macro stored in <a-z>. |
@@ | Replay the last-played macro. |
10@a | Replay macro a 10 times. |
Vim is a modal text editor where most keystrokes are commands rather than text input. The reference page above is the cheat sheet; this companion explains the underlying grammar that makes Vim composable.
The modes
| Mode | Entered by | What it does |
|---|---|---|
| Normal | default; Esc from Insert or Visual mode | Commands and motions |
| Insert | i, a, o, I, A, O | Type text |
| Visual | v (char), V (line), Ctrl-v (block) | Select text |
| Command-line | : | Execute Ex commands |
| Command-line search | / (forward), ? (backward) | Search for text |
| Replace | R | Overwrite |
The most common confusion for new users: pressing keys in Normal mode does things instead of typing letters. Press i to enter Insert mode; press Esc to return.
The grammar: operator + motion
Vim commands often read as “verb + noun”:
| Operator (verb) | + | Motion (noun) | = | Effect |
|---|---|---|---|---|
d (delete) | + | w (word) | = | dw — delete from cursor toward the next word |
c (change) | + | e (end of word) | = | ce — change to end of word |
y (yank) | + | $ (end of line) | = | y$ — yank to end of line |
> (indent) | + | ip (inner paragraph) | = | >ip — indent paragraph |
= (auto-indent) | + | G (end of file) | = | =G — auto-indent to end |
Doubling the operator targets the current line: dd deletes a line, yy yanks a line, cc changes a line.
Adding a count repeats: 3dw deletes three words; 2yy yanks two lines; 5>> indents five lines.
The common operators
| Operator | What it does |
|---|---|
d | Delete |
c | Change (delete and enter Insert mode) |
y | Yank (copy) |
> | Indent right |
< | Indent left |
= | Auto-indent |
gu | Lowercase |
gU | Uppercase |
g~ | Toggle case |
p and P are put commands, not operators awaiting a motion. A linewise register is put below or above the current line.
The common motions
| Motion | Where it goes |
|---|---|
h j k l | left / right by character; down / up by line |
w | next word start |
e | next word end |
b | previous word start |
0 | start of line |
^ | first non-blank of line |
$ | end of line |
gg | top of file |
G | bottom of file |
NG (replace N with a number) | line N; :N is the Ex alternative |
} | next paragraph |
{ | previous paragraph |
f<char> | next occurrence of char on line |
t<char> | up to (not including) next char |
* | next occurrence of word under cursor |
n | next search result |
% | matching bracket / paren |
Text objects
Operators can target text objects — semantic regions like “a word,” “a sentence,” “a paragraph,” “the contents of these brackets”:
| Object | Modifier | Examples |
|---|---|---|
w | word | daw (delete a word, including space) / diw (delete inner word, not space) |
s | sentence | das / dis |
p | paragraph | dap / dip |
( ) b | parens | da( / di( |
{ } B | curly braces | da{ / di{ |
[ ] | square brackets | da[ / di[ |
" | double quotes | da" / di" |
' | single quotes | da' / di' |
t | XML tag | dat / dit |
a and i depend on the text object. Around-parentheses includes the parentheses; around-word includes adjoining whitespace where available. They do not all share one trailing-whitespace rule. ci" (change inner quotes) is one of the most useful combinations — replaces the contents of a string literal in one step.
Insert-mode helpers
Once in Insert mode (i), useful commands:
| Key | What it does |
|---|---|
Ctrl-w | Delete previous word |
Ctrl-u | Delete text entered during this insertion on the current line; further deletion depends on backspace settings |
Ctrl-r <reg> | Insert from register |
Ctrl-n / Ctrl-p | Autocomplete next / previous |
Ctrl-x Ctrl-f | Filename autocomplete |
Ctrl-x Ctrl-l | Whole-line autocomplete |
Ex commands
: enters command-line mode. Common ones:
| Command | What it does |
|---|---|
:w | Write file |
:q | Quit |
:wq | Write and quit |
:x | Write only if modified, then quit |
:q! | Quit without saving |
:e <file> | Edit (open) file |
:%s/old/new/g | Substitute (replace) all matches |
:%s/old/new/gc | Substitute with confirm |
:set number | Show line numbers |
:vsp <file> | Open in vertical split |
:tabnew <file> | Open in new tab |
Registers
Vim has multiple clipboards (registers). Specify with "<letter> before an operator:
"ayy yank line into register a
"ap paste from register a
"+y yank into system clipboard (with clipboard support)
"+p paste from system clipboard
:reg show all register contents
The unnamed register "" is the default — what dd and yy use. "_dd deletes without overwriting the unnamed register (the “black hole” register).
Macros
Record a sequence of commands and replay:
qa start recording into register a
... (commands)
q stop recording
@a replay
@@ replay last macro
3@a replay 3 times
Macros are how Vim users do bulk edits. Record once; replay many times.
Common pitfalls
- Stuck in Insert mode. Press
Esc(orCtrl-[). - Stuck in some other mode.
Escuntil you’re in Normal. - Accidentally typed
:and pressed nothing. PressEscorEnter(with empty input). Caps Lockmapped to weird keys. A common cause of “Vim is doing strange things” — your Caps Lock might be mapped to Ctrl or Esc.- Forgetting that
Ctrl-cdoesn’t always equalEsc. In Insert mode,Ctrl-cskips abbreviation checking and theInsertLeaveautocommand;Escdoes not. - A write fails. Preserve the buffer with
:w <different-file>in a location you can write, then inspect permissions.:w!can override Vim’s read-only option, but cannot grant operating-system permissions.
For other developer references, see git commands, HTTP status codes, regex cheat sheet.
Sources and scope
Checked September 27, 2026: Vim motions and text objects, Insert mode, and writing / quitting. Mappings and options can change default key behavior.