Skip to content

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.

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.

CommandDescription
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.

CommandDescription
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>&lt;operator&gt;&lt;motion&gt;</code>, e.g. <code>d3w</code> = delete 3 words, <code>cit</code> = change inside HTML tag.

CommandDescription
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).

CommandDescription
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

CommandDescription
/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

CommandDescription
: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

CommandDescription
: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

CommandDescription
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

CommandDescription
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

ModeEntered byWhat it does
Normaldefault; Esc from Insert or Visual modeCommands and motions
Inserti, a, o, I, A, OType text
Visualv (char), V (line), Ctrl-v (block)Select text
Command-line:Execute Ex commands
Command-line search/ (forward), ? (backward)Search for text
ReplaceROverwrite

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

OperatorWhat it does
dDelete
cChange (delete and enter Insert mode)
yYank (copy)
>Indent right
<Indent left
=Auto-indent
guLowercase
gUUppercase
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

MotionWhere it goes
h j k lleft / right by character; down / up by line
wnext word start
enext word end
bprevious word start
0start of line
^first non-blank of line
$end of line
ggtop of file
Gbottom 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
nnext 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”:

ObjectModifierExamples
wworddaw (delete a word, including space) / diw (delete inner word, not space)
ssentencedas / dis
pparagraphdap / dip
( ) bparensda( / di(
{ } Bcurly bracesda{ / di{
[ ]square bracketsda[ / di[
"double quotesda" / di"
'single quotesda' / di'
tXML tagdat / 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:

KeyWhat it does
Ctrl-wDelete previous word
Ctrl-uDelete text entered during this insertion on the current line; further deletion depends on backspace settings
Ctrl-r <reg>Insert from register
Ctrl-n / Ctrl-pAutocomplete next / previous
Ctrl-x Ctrl-fFilename autocomplete
Ctrl-x Ctrl-lWhole-line autocomplete

Ex commands

: enters command-line mode. Common ones:

CommandWhat it does
:wWrite file
:qQuit
:wqWrite and quit
:xWrite only if modified, then quit
:q!Quit without saving
:e <file>Edit (open) file
:%s/old/new/gSubstitute (replace) all matches
:%s/old/new/gcSubstitute with confirm
:set numberShow 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 (or Ctrl-[).
  • Stuck in some other mode. Esc until you’re in Normal.
  • Accidentally typed : and pressed nothing. Press Esc or Enter (with empty input).
  • Caps Lock mapped 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-c doesn’t always equal Esc. In Insert mode, Ctrl-c skips abbreviation checking and the InsertLeave autocommand; Esc does 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.