Vim (Advanced) keyboard shortcuts

Vim 9.2's quick reference (quickref.txt) retold section by section: motions, text objects, the Ex command line, windows, quickfix and folding, with one keymap for every system. Typed commands like gJ or :wall are case-sensitive; chords use key names, so Ctrl + W, S is CTRL-W then s. Braces and square brackets mark a part to fill in, as in :cc [nr], and <CR> means Enter. The option list and Ctrl-W commands needing a capital letter are left out.

602 shortcuts in 40 sections. Checked row by row against Vim help: quickref.txt, the quick reference guide (Vim 9.2, tag v9.2.1169) on . Edited by Jay.

Left-right motions 17

N in the quick reference stands for an optional count typed before a command; the rows here mention the count only where it changes what the command does.

ActionShortcut
Left one characterCtrl + H, Backspace and the Left arrow are the same motion; a count multiplies it.h
Right one characterSpace and the Right arrow act as the same motion; a count moves that many characters.l
First character of lineColumn one, indentation included; the Home key is the same motion.0
First non-blank of lineLands where the text starts, on the first character that is not a space or tab.^
Last character of lineWith a count N it ends on the line N-1 below; the End key is the same motion.$
First character of screen lineDiffers from 0 only when a long line wraps: it stays on the current screen row.g0
First non-blank of screen lineThe wrapped-line counterpart of ^, working on the screen row the cursor is in.g^
Last character of screen lineOn a wrapped line it stops at the right edge of the current screen row, not at the real line end.g$
Middle of screen lineWorks on the screen row, where gM works on the text of the whole line.gm
Middle of text lineHalfway through the characters of the line, wherever that falls on screen.gM
Go to column NType the column number first; without one the cursor goes to column 1.|
Onto next occurrence of a characterSearches rightwards within the line and lands on the character; a count picks the Nth one.f{char}
Onto previous occurrence of a characterSearches leftwards within the line and lands on the character; a count picks the Nth one.F{char}
Up to next occurrence of a characterLike f, but the cursor stops one position before the character.t{char}
Back to just after a characterLike F, but the cursor stops one position short of the character it finds.T{char}
Repeat last character jumpReuses the character and direction of the latest f, t, F or T command.;
Repeat character jump, reversedSame character, opposite direction: after f it searches leftwards.,

Up-down motions 10

ActionShortcut
Up one lineCtrl + P and the Up arrow are the same motion; a count gives the number of lines.k
Down one lineCtrl + J, Ctrl + N and the Down arrow are the same motion.j
Up to first non-blankLike k, except that the cursor ends at the start of the text on that line.-
Down to first non-blankLike j, but the cursor ends where the text of the line starts; Ctrl + M and Enter do the same.+
First non-blank, N-1 lines downWithout a count it stays on the current line and goes to the start of its text._
Go to line N or last lineWithout a count it goes to the end of the file.G
Go to line N or first lineWithout a count it goes to the top of the file.gg
Go to a percentage of the fileThe count is required: 50% jumps halfway down, while a bare % is the bracket-matching command.N%
Up one screen lineMoves within a wrapped line row by row, where k would skip the whole line.gk
Down one screen lineMoves within a wrapped line row by row, where j would skip the whole line.gj

Text object motions 28

ActionShortcut
Start of next wordWords end at punctuation as well as at blanks, unlike the WORDs that W uses.w
Start of next WORDA WORD is any run of non-blank characters, so it hops over punctuation.W
End of word, forwardsLands on the last character of a word instead of the first; a count picks the Nth word.e
End of WORD, forwardsSame as e, with blank-separated WORDs as the unit.E
Start of previous wordMoves backwards word by word; a count gives the number of words.b
Start of previous WORDMoves backwards over blank-separated WORDs, ignoring punctuation inside them.B
End of previous wordThe backward counterpart of e: it lands on a last character.ge
End of previous WORDThe backward counterpart of E, with blank-separated WORDs as the unit.gE
Next sentenceMoves forward sentence by sentence; a count gives how many.)
Previous sentenceMoves backward sentence by sentence; a count gives how many.(
Forward one paragraphTakes a count for the number of paragraphs to pass.}
Back one paragraphTakes a count for the number of paragraphs to go back over.{
Next section startA count moves that many sections toward the end of the file.]]
Previous section startA count moves that many sections toward the top of the file.[[
Next section endLike ]], but it stops where a section ends rather than where it begins.][
Previous section endLike [[, but it stops where a section ends rather than where it begins.[]
Back to unclosed (Goes to the opening parenthesis that encloses the cursor; a count leaves several nesting levels.[(
Back to unclosed {Goes to the opening brace of the block the cursor is in; a count leaves several levels.[{
Previous method startWritten for Java code; a count goes back several methods.[m
Previous method endWritten for Java code; it stops where an earlier method closes.[M
Forward to unclosed )Goes to the closing parenthesis that encloses the cursor.])
Forward to unclosed }Goes to the closing brace of the block the cursor is in.]}
Next method startWritten for Java code; a count goes forward several methods.]m
Next method endWritten for Java code; it stops where a later method closes.]M
Enclosing #if or #else, backwardsFor C preprocessor blocks: goes to the conditional line that the cursor is inside.[#
Enclosing #else or #endif, forwardsFor C preprocessor blocks: goes to the line that closes the conditional around the cursor.]#
Comment start, backwardsLooks for the /* that opens a C-style comment.[*
Comment end, forwardsLooks for the */ that closes a C-style comment.]*

Pattern searches 12

ActionShortcut
Search forward for a patternPress Enter to run it; a search offset may follow a closing slash, and a count finds the Nth match./{pattern}
Search backward for a patternWorks toward the top of the file; a search offset may follow a closing question mark.?{pattern}
Repeat search forwardsAn empty pattern reuses the last one, always searching toward the end of the file./<CR>
Repeat search backwardsAn empty pattern reuses the last one, always searching toward the top of the file.?<CR>
Repeat last searchKeeps the direction the search was started in; a count jumps to the Nth match.n
Repeat search, opposite directionAfter a / search it goes backwards, after ? forwards.N
Search forward for word under cursorFinds the identifier as a whole word only; g* drops that restriction.*
Search backward for word under cursorWhole-word matches only, going toward the top of the file.#
Forward search, partial matches tooLike *, but the identifier may also be part of a longer word.g*
Backward search, partial matches tooLike #, but the identifier may also be part of a longer word.g#
Go to local declarationUses the identifier under the cursor; gD looks for a global declaration instead.gd
Go to global declarationUses the identifier under the cursor; gd looks for a local declaration instead.gD

Search pattern items 27

ActionShortcut
Any single characterWith 'nomagic' set this is written \. instead..
Start of line^
End of line$
Start of a word\<
End of a word\>
One character from a rangeWith 'nomagic' set this is written \[a-z] instead.[a-z]
One character outside a rangeWith 'nomagic' set this is written \[^a-z] instead.[^a-z]
Identifier character\i
Identifier character, no digits\I
Keyword character\k
Keyword character, no digits\K
File name character\f
File name character, no digits\F
Printable character\p
Printable character, no digits\P
White space character\s
Non-white space character\S
Esc character\e
Tab character\t
Carriage return character\r
Backspace character\b
Zero or more of preceding atomWith 'nomagic' set this is written \* instead.*
One or more of preceding atom\+
Optional preceding atomThe atom before it may appear once or be absent.\=
Two to five of preceding atomThe two numbers are the smallest and largest repeat counts allowed.\{2,5}
Either of two alternativesThe pattern matches when the part on one side of it matches.\|
Group into one atomWrite the sub-pattern between the two halves so that a following count applies to all of it.\(\)

Search offsets 8

ActionShortcut
Lines below the matchWritten after the closing / or ? of a search; the cursor lands in column 1 of that line.[num]or+[num]
Lines above the matchThe cursor lands in column 1, that many lines over the matching line.-[num]
Right of the match ende alone puts the cursor on the last character of the match; the number moves it further right.e[+num]
Left of the match endCounts characters backwards from the last character of the match.e[-num]
Right of the match startCounts characters forwards from the first character of the match.s[+num]
Left of the match startCounts characters backwards from the first character of the match.s[-num]
Same as the s offsetsb stands for begin: the count runs from the first character of the match, as with s.b[+num]orb[-num]
Chain a second searchOnce the first pattern is found, the search written after the semicolon runs from there.;{search-command}

Marks and jumps 16

ActionShortcut
Mark the cursor positionMarks a to z are kept per file; A to Z also remember which file they are in.m{a-zA-Z}
Jump to a lowercase markOnly reaches marks set in the file being edited.`{a-z}
Jump to an uppercase markSwitches to the file that holds the mark when it is a different one.`{A-Z}
Jump to where Vim was last exitedThe numbered marks record the cursor position of earlier Vim sessions.`{0-9}
Return to pre-jump positionGoes to where the cursor was before the latest jump command, for example a search or G.``
Cursor position of last edit sessionTakes the cursor to where it was the last time this file was left.`"
Start of last operated-on textRefers to what the latest operator or put command worked on.`[
End of last operated-on textThe far end of what the latest operator or put command touched.`]
Start of last Visual areaStill set after Visual mode has ended, so the old selection can be revisited.`<
End of last Visual areaMarks the opposite corner of the selection made most recently.`>
Position of last changeRefers to the latest edit made in the current file.`.
Line of a mark, first non-blankEvery backtick mark jump has this apostrophe form, which ignores the stored column.'{a-zA-Z0-9}
Show the active marksPrints the marks that are set, as a list on the command line.:marks
Back through the jump listEach press steps one jump further back; a count goes back N positions at once.Ctrl+O
Forward through the jump listMoves forward again after Ctrl + O; a count goes N positions at once.Ctrl+I
Print the jump listFull name :jumps; shows the positions that Ctrl + O and Ctrl + I move through.:ju

Various motions 6

ActionShortcut
Matching bracket or #if partWorks for parentheses, brackets, braces, C comments and #if, #else, #endif lines.%
Top of windowA count N puts the cursor on the Nth line counted from the top instead.H
Middle of windowPuts the cursor on the centre line of the visible text, at its first non-blank.M
Bottom of windowA count N selects the Nth line counted from the bottom.L
Go to byte NCounts bytes from the start of the buffer; the count is typed before the command.go
Go to a byte offsetFull name :goto; the Ex form of the go command.:go [off]

Using tags 19

ActionShortcut
Jump to a tagGoes to the definition of the named tag, switching files when needed; full name :tag.:ta {tag}
Newer tag in the tag listMoves forward again through tags that were jumped back from.:[count]ta
Follow the tag under the cursorFails when the current buffer has unsaved changes.Ctrl+]
Choose among matching tagsFull name :tselect; prints every match and waits for a choice.:ts [tag]
Jump, or choose when ambiguousGoes straight to a unique match and offers the list only when several tags fit; :tj for short.:tjump [tag]
Jump and fill the location listBesides jumping, it records every matching tag in the location list; :lt for short.:ltag [tag]
Print the tag listShows the tags that have been jumped through, the list Ctrl + T walks back along.:tags
Jump back from a tagReturns to where the tag jump was made; a count returns from the Nth older one.Ctrl+T
Jump back in the tag listFull name :pop; the Ex form of Ctrl + T, taking a count in front.:po
Next matching tagWhen several tags match, moves on to the following one; :tn for short.:tnext
Previous matching tagFull name :tprevious; steps back through the tags that matched.:tp
First matching tagFull name :trewind; with a count it goes to that numbered match.:tr
Last matching tagFull name :tlast; goes to the final entry of the matches.:tl
Show a tag in the preview windowOpens the preview window on the definition instead of jumping there; :pt for short.:ptag {tag}
Preview the tag under the cursorDoes what Ctrl + ] does, but shows the result in the preview window.Ctrl+Wthen}
Choose a tag for the preview windowFull name :ptselect; the preview-window form of :tselect.:pts
Preview a tag, choosing if neededThe preview-window form of :tjump; :ptj for short.:ptjump
Close the preview windowShuts the window that the tag preview commands opened; :pc for short.:pclose
Close the preview windowThe Normal-mode key for what :pclose does.Ctrl+WthenZ

Scrolling 13

ActionShortcut
Scroll window down by linesShows one more line at the bottom, or N more with a count.Ctrl+E
Scroll down half a windowGive a count to scroll that exact number of lines.Ctrl+D
Forward a full pageMoves down the buffer by whole windows; a count gives the number of pages.Ctrl+F
Scroll window up by linesShows one more line at the top, or N more with a count.Ctrl+Y
Scroll up half a windowGive a count to scroll that exact number of lines toward the top.Ctrl+U
Back a full pageMoves up the buffer by whole windows; a count gives the number of pages.Ctrl+B
Redraw with cursor line on topBoth spellings scroll the text so the current line becomes the first one shown.z<CR>orzt
Redraw with cursor line centredBoth spellings scroll the text so the current line sits halfway down the window.z.orzz
Redraw with cursor line at bottomBoth spellings scroll the text so the current line becomes the last one shown.z-orzb
Scroll screen right by charactersNeeds 'wrap' switched off; a count gives the number of characters.zh
Scroll screen left by charactersNeeds 'wrap' switched off; moves the text the other way from zh.zl
Scroll half a screen rightNeeds 'wrap' switched off; jumps sideways by half the width of the screen.zH
Scroll half a screen leftNeeds 'wrap' switched off; the half-screen jump in the direction of zl.zL

Inserting text 9

ActionShortcut
Insert text after the cursorWith a count the typed text is inserted that many times when Insert mode ends.a
Insert text at end of lineMoves to the end of the line first, whatever column the cursor was in.A
Insert in front of the cursorThe Insert key does the same; a count repeats what was typed.i
Insert text at first non-blankStarts typing where the text of the line begins, after any indent.I
Insert at the very start of lineUnlike I it ignores indentation and begins in the first column.gI
New line below, then insertThe cursor moves to a fresh line beneath the current one, ready for typing.o
New line above, then insertThe cursor moves to a fresh line over the current one, ready for typing.O
Start Insert mode from ExWith ! added it appends at the end of the line, as A does; :star for short.:startinsert
Start Replace mode from ExWith ! added it starts at the end of the line; :startr for short.:startreplace

Insert mode keys 8

ActionShortcut
End Insert modeGoes back to Normal mode; an abbreviation typed just before it is still expanded.Esc
End Insert mode, no abbreviationLeaves like Esc, except that a pending abbreviation is not expanded.Ctrl+C
Run one command, keep insertingThe single Normal-mode command is carried out and typing continues afterwards.Ctrl+Othen{command}
Move the cursor while insertingThe arrow keys work without leaving Insert mode.LeftorRightorUporDown
Move one word while insertingJumps a word to the left or to the right and stays in Insert mode.Shift+LeftorShift+Right
Move one screenful while insertingUp goes a screen back in the text, Down a screen ahead.Shift+UporShift+Down
Insert point to end of linePlaces the insertion point behind the final character of the current line.End
Insert point to start of lineGoes to column one of the line, indentation included.Home

Special keys in Insert mode 18

ActionShortcut
Insert next character literallyThe next key is taken as text even when it is a special key; digits typed after the chord give a decimal byte value.Ctrl+Vthen{char}
Start a new lineCR is Vim's name for the Enter key; NL, the line-feed key, also works.<CR>orCtrl+MorCtrl+J
Copy character from line belowInserts whatever character sits directly under the cursor position, one per press.Ctrl+E
Copy character from line aboveInserts whatever character sits directly over the cursor position, one per press.Ctrl+Y
Insert last inserted text againRepeats what was typed during the previous stay in Insert mode.Ctrl+A
Repeat last insert and leaveLike Ctrl + A, then returns to Normal mode straight away.Ctrl+@
Put a register at the cursorType the register name after the chord; its text is inserted as if typed.Ctrl+Rthen{register}
Complete with next matchLooks forward for words that begin with what is typed in front of the cursor.Ctrl+N
Complete with previous matchLooks backward for words that begin with what is typed in front of the cursor.Ctrl+P
Start a completion submodeThe key that follows selects the kind of completion to use.Ctrl+X
Erase the previous characterBoth keys remove the character to the left of the insertion point.BackspaceorCtrl+H
Erase the character under cursorRemoves the character at the insertion point without moving left.Delete
Erase the previous wordRemoves the word to the left of the insertion point in one go.Ctrl+W
Erase what was typed on the lineWipes every character typed into the current line.Ctrl+U
Add one indent levelIndents the current line by one 'shiftwidth' while the cursor stays in the text.Ctrl+T
Remove one indent levelTakes one 'shiftwidth' of indent off the current line.Ctrl+D
Remove all indentType a zero and then the chord; the line loses its whole indent.0thenCtrl+D
Remove indent for this line onlyThe indent is removed from the current line and brought back on the next one.^thenCtrl+D

Digraphs and special inserts 6

ActionShortcut
List digraphsFull name :digraphs; shows the two-character codes and the characters they produce.:dig
Define a digraphThe two characters will produce the character with the given decimal number.:dig {char1}{char2} {number}
Enter a digraphWorks in Insert and Command-line mode: the two characters typed next combine into one special character.Ctrl+Kthen{char1}then{char2}
Enter a digraph with BackspaceOnly when the 'digraph' option is set: type one character, Backspace, then the other.{char1} <BS> {char2}
Insert a file under the cursor lineFull name :read; the text of the file is added after the current line.:r [file]
Insert command outputRuns the shell command and puts what it prints under the cursor line.:r! {command}

Deleting text 8

ActionShortcut
Delete characters forwardsRemoves the character under the cursor; a count also takes the ones after it.xorDelete
Delete characters backwardsRemoves the character to the left of the cursor; a count takes more of them.X
Delete what a motion coversAn operator: the text between the cursor and the place the motion ends is removed.d{motion}
Delete whole linesOne line, or N lines with a count, starting at the cursor line.dd
Delete rest of lineWith a count it also removes the N-1 lines that follow.D
Join with next lineRemoves the line break and puts a space where the lines meet.J
Join lines without spacesThe lines are glued together exactly, with nothing inserted at the seam.gJ
Delete a range of linesFull name :delete; the lines of the range go into register x when one is named.:d [x]

Copying and moving text 11

ActionShortcut
Pick the register to useTyped before a delete, yank or put command, it names the register that command works with."{char}
Display register contentsFull name :registers; prints every register with the text stored in it.:reg
Show selected registersList the register names after the command to see only those.:reg {arg}
Yank what a motion coversAn operator: the text up to where the motion ends is copied, not removed.y{motion}
Yank whole linesCopies the cursor line, or N lines with a count.yyorY
Put register text after cursorA count inserts the text that many times; name a register first to choose which one.p
Put register text before cursorThe mirror of p: the text lands in front of the cursor position.P
Put after, matching indentLike p, but the pasted lines take the indent of the current line.]p
Put before, matching indentLike P, but the pasted lines take the indent of the current line.[p
Put after, cursor past new textLike p, except that the cursor ends just beyond what was pasted.gp
Put before, cursor past new textLike P, except that the cursor ends just beyond what was pasted.gP

Changing text 23

ActionShortcut
Replace characters in placeOverwrites the character under the cursor, or N characters with a count, without entering Insert mode.r{char}
Replace keeping the layoutLike r, but a Tab is treated as the screen columns it fills, so text after it does not shift.gr{char}
Start Replace modeTyping overwrites the existing text; a count repeats the typed text when the mode ends.R
Start virtual Replace modeOverwrites by screen column, so tabs and the alignment of later text stay as they were.gR
Change what a motion coversAn operator: the covered text is removed and Insert mode starts in its place.c{motion}
Change whole linesThe text of the line, or of N lines, is replaced by what is typed next.ccorS
Change rest of lineFrom the cursor to the line end, plus N-1 further lines with a count.C
Change charactersN characters from the cursor onwards are replaced by the text typed next.s
Switch case and move onFlips upper and lower case of the character under the cursor, then steps right; a count does N characters.~
Switch case over a motionUpper case becomes lower and lower becomes upper across the covered text.g~{motion}
Make a motion's text lowercaseEvery capital in the covered text becomes a small letter.gu{motion}
Make a motion's text uppercaseEvery small letter in the covered text becomes a capital.gU{motion}
Rot13-encode over a motionRotates each letter thirteen places in the alphabet; doing it twice restores the text.g?{motion}
Add N to a numberChanges the number at the cursor, or else the next one on the line; without a count it adds 1.Ctrl+A
Subtract N from a numberChanges the number at the cursor, or else the next one after it; without a count it takes off 1.Ctrl+X
Shift lines left over a motionEach covered line moves one 'shiftwidth' toward the left margin.<{motion}
Shift lines leftMoves the cursor line, or N lines with a count, one 'shiftwidth' left.<<
Shift lines right over a motionEach covered line moves one 'shiftwidth' away from the left margin.>{motion}
Shift lines rightMoves the cursor line, or N lines with a count, one 'shiftwidth' right.>>
Format lines over a motionBreaks and joins the lines so that they fit within 'textwidth' columns.gq{motion}
Centre linesFull name :center; centres the lines of the range, within the given width when one is written.:ce [width]
Left-align linesFull name :left; the optional number sets the indent the lines get.:le [indent]
Right-align linesFull name :right; lines of the range are pushed against the right edge of the given width.:ri [width]

Complex changes and shell commands 12

ActionShortcut
Filter lines through a commandThe lines the motion covers are sent to the external command and replaced by its output.!{motion}{command}
Filter N lines through a commandThe cursor line, or N lines with a count, is replaced by what the command prints.!!{command}
Filter a range through a commandThe Ex form of the filter: the lines of the range are replaced by the output.:[range]! {command}
Re-indent lines over a motionPasses the lines to the program named in 'equalprg'; when that option is empty Vim's own indenting is used.={motion}
Re-indent linesDoes for the cursor line, or N lines, what = does over a motion.==
Substitute text in linesUsually typed :s; g replaces every match on a line and c asks before each one.:[range]s[ubstitute]/{pattern}/{string}/[g][c]
Repeat last substitute, new rangeRuns the previous :s again on other lines, with the flags given here.:[range]s[ubstitute] [g][c]
Repeat substitute on this lineReruns the previous :s on the cursor line, dropping the flags it was given.&
Retab the bufferFull name :retab; sets 'tabstop' to the new value and rewrites white space so the text keeps its look.:ret [tabstop]
Open a shell from VimRuns an interactive shell; :sh is the short form.:shell
Execute a command in a shellThe buffer is not changed, unlike the filter forms that carry a range.:!{command}
Run keyword lookup programHands the word under the cursor to the 'keywordprg' program, normally man.K

Visual mode 24

ActionShortcut
Start characterwise Visual modeMove the cursor to grow the highlighted area, then give an operator.v
Start Visual mode by linesComplete lines are highlighted as the cursor moves up or down.V
Start Visual mode by blocksHighlights a rectangle between the starting point and the cursor.Ctrl+V
Swap ends of the selectionThe cursor jumps to the other end of the highlighted area, which can then be extended from there.o
Reselect the previous areaStarts Visual mode again on the text that was highlighted last time.gv
Switch to characterwise or stopIn Visual mode: changes a line or block selection to characters, or ends the mode when already characterwise.v
Switch to linewise or stopIn Visual mode: changes the selection to whole lines, or ends the mode when already linewise.V
Switch to blockwise or stopIn Visual mode: changes the selection to a block, or ends the mode when already blockwise.Ctrl+V
Delete the selectionRemoves the highlighted text and returns to Normal mode.d
Yank the selectionThe highlighted text is copied into a register and the buffer is left as it was.y
Change the selectionThe highlighted text is removed and Insert mode starts for the replacement.c
Join the selected linesAll highlighted lines become one line, with spaces where they met.J
Join selected lines, no spacesLike J on a selection, but nothing is inserted where the lines met.gJ
Switch case of the selectionUpper case turns to lower and lower to upper throughout the highlighted text.~
Lowercase the selectionTurns every highlighted capital into a small letter.u
Uppercase the selectionTurns every highlighted small letter into a capital.U
Rot13-encode the selectionEach highlighted letter is rotated thirteen places in the alphabet.g?
Fill a block with one characterBlockwise selection: every character in the block is replaced by the one typed.r{char}
Change every line of a blockBlockwise selection: the text typed replaces the selected part on each line.c
Change block lines to line endBlockwise selection: each selected line is replaced from the block to its end by the typed text.C
Insert in front of a blockFor a block selection: one piece of typed text is placed at the start of the block on each line.I
Append after a blockFor a block selection: one piece of typed text is placed after the end of the block on each line.A
Filter the selectionThe highlighted lines are replaced by what the external command prints.!{command}
Re-indent the selectionThe highlighted lines are passed through 'equalprg' or Vim's own indenting.=

Text objects 22

ActionShortcut
Word plus white spaceThe word the cursor is in together with the white space beside it.aw
Word onlyOnly the characters of the word itself, wherever in it the cursor sits.iw
WORD plus white spaceA blank-separated WORD and the white space that follows or precedes it.aW
WORD onlyA blank-separated WORD without any surrounding white space.iW
Sentence plus white spaceThe sentence around the cursor including the white space after it.as
Sentence onlyThe sentence around the cursor, stopping before the white space that follows.is
Paragraph plus blank linesEvery line of it, and also the empty lines that separate it from what follows.ap
Paragraph onlyThe lines of the paragraph alone, stopping before the blank line.ip
Parenthesis block, with ( )From the ( before the cursor to its matching ), both included.ab
Inside a parenthesis blockWhat stands between the enclosing ( and ), leaving the two characters in place.ib
Brace block, with { }From the enclosing { to its matching }, both included.aB
Inside a brace blockThe text between the enclosing { and }, without the braces themselves.iB
Angle-bracket block, with bracketsFrom an opening angle bracket to the closing one, both included.a>
Inside an angle-bracket blockThe text enclosed by a pair of angle brackets, leaving the pair itself.i>
Tag block, with its tagsA whole XML or HTML element: opening tag, content and closing tag.at
Inside a tag blockWhat an element contains, with the opening and closing tags left out.it
Single-quoted string, with quotesThe text in single quotes together with the two quote characters.a'
Inside a single-quoted stringThe text in single quotes, leaving the quote characters where they are.i'
Double-quoted string, with quotesThe text in double quotes together with the two quote characters.a"
Inside a double-quoted stringThe text in double quotes, leaving the quote characters where they are.i"
Backtick string, with backticksThe text in backticks together with the two backtick characters.a`
Inside a backtick stringThe text in backticks, leaving the backtick characters where they are.i`

Undo, redo and repeating 16

ActionShortcut
Undo changesReverts the most recent change, or the last N changes with a count.u
Reapply undone changesBrings back what u removed, one change per press or N with a count.Ctrl+R
Restore the last changed lineBrings the line edited most recently back to its state before those edits.U
Repeat the last changePerforms the latest editing command again; when a count is typed it overrides the earlier count..
Record keys into a registerStarts a recording: keystrokes are saved under the chosen letter until a lone q ends it.q{a-z}
Append keys to a registerA capital letter adds the new keystrokes to what the lowercase register already holds.q{A-Z}
End the recordingPressed while recording, it closes the register so it can be replayed.q
Execute a registerTreats the text of the register as typed commands, N times over when a count is given.@{a-z}
Execute the same register againRepeats the previous @ command without naming the register.@@
Run a register as an Ex commandThe register text is executed as command-line input rather than as Normal-mode keys.:@{a-z}
Repeat the last :@ commandRuns once more the register that was last executed with the Ex form.:@@
Run a command on matching linesUsually typed :g; without a command the matching lines are printed.:[range]g[lobal]/{pattern}/[cmd]
Run a command on non-matching linesThe inverse of :g: the command acts on the lines the pattern does not match.:[range]g[lobal]!/{pattern}/[cmd]
Source a script fileFull name :source; each line of the file is run as an Ex command, or as Normal-mode keys when ! is added.:so {file}
Pause for some secondsFull name :sleep; Vim does nothing for the given number of seconds.:sl [sec]
Sleep for N secondsThe Normal-mode form of :sleep; the count is the number of seconds.gs

Key mapping 20

ActionShortcut
Map keys for Normal and Visual modeTyping {lhs} then acts as if {rhs} had been typed, and {rhs} may itself contain mappings.:map {lhs} {rhs}
Mapping for Insert and Command-lineThe ! variant defines the mapping for the two typing modes instead.:map! {lhs} {rhs}
Map without remappingThe right-hand side is used literally, so mappings inside it are not applied; ! works as with :map.:noremap {lhs} {rhs}
Remove a Normal and Visual mappingDeletes the mapping whose left-hand side is given; :unm for short.:unmap {lhs}
Remove an Insert or Cmdline mappingDeletes the mapping defined with :map! for the same keys.:unmap! {lhs}
List Normal and Visual mappingsWith an argument only mappings that start with those keys are shown; add ! for the Insert and Command-line ones.:map [lhs]
Command-line mapping commandsWork as :map!, :unmap! and :noremap! do, limited to Command-line mode.:cmap / :cunmap / :cnoremap
Insert mode mapping commandsWork as :map!, :unmap! and :noremap! do, limited to Insert mode.:imap / :iunmap / :inoremap
Normal mode mapping commandsWork as :map, :unmap and :noremap do, limited to Normal mode.:nmap / :nunmap / :nnoremap
Visual mode mapping commandsWork as :map, :unmap and :noremap do, limited to Visual mode.:vmap / :vunmap / :vnoremap
Operator-pending mapping commandsApply only while Vim waits for a motion after an operator such as d or y.:omap / :ounmap / :onoremap
Clear Normal and Visual mappingsFull name :mapclear; with ! it clears the Insert and Command-line mappings instead.:mapc
Clear Insert mode mappingsFull name :imapclear; every mapping defined for Insert mode is removed.:imapc
Clear Visual mode mappingsFull name :vmapclear; removes all mappings that apply in Visual mode.:vmapc
Clear Operator-pending mappingsFull name :omapclear; removes the mappings used after an operator.:omapc
Clear Normal mode mappingsFull name :nmapclear; mappings of other modes are left alone.:nmapc
Clear Command-line mappingsFull name :cmapclear; affects only mappings for typing on the command line.:cmapc
Save mappings and settingsWrites the current mappings, abbreviations and option settings to a file, .exrc unless another name is given; ! overwrites.:mkexrc [file]
Save settings as a vimrcDoes what :mkexrc does with .vimrc as the default file name; :mkv for short.:mkvimrc [file]
Save the sessionStores open files and window layout along with the settings, so the work can be resumed later; :mks for short.:mksession [file]

Abbreviations 10

ActionShortcut
Define an abbreviationTyping {lhs} as a word is then expanded to {rhs}; :ab for short.:abbreviate {lhs} {rhs}
Show abbreviations for a prefixLists the abbreviations whose short form begins with the given text.:abbreviate {lhs}
Show all abbreviationsWithout arguments the whole list is printed.:abbreviate
Remove an abbreviationThe short form no longer expands; :una for short.:unabbreviate {lhs}
Abbreviate without remappingLike :ab, except that mappings are not applied to the expanded text.:noreabbrev [lhs] [rhs]
Insert mode abbreviation commandsDefine, remove and define-without-remap, limited to typing in Insert mode.:iab / :iunab / :inoreab
Command-line abbreviation commandsDefine, remove and define-without-remap, limited to the command line.:cab / :cunab / :cnoreab
Clear every abbreviationNothing is left in either mode; :abc for short.:abclear
Clear Command-line abbreviationsOnly abbreviations for the command line go; :cabc for short.:cabclear
Clear Insert mode abbreviationsOnly abbreviations for Insert mode go; :iabc for short.:iabclear

Setting options 15

ActionShortcut
Show changed optionsWith no argument it lists every option whose value differs from the default.:set
Show all optionsLists every option except the terminal ones.:set all
Show terminal optionsLists the termcap entries, the options that describe the terminal.:set termcap
Set a boolean optionTurns an on/off option on; given a string or number option it only displays the value.:set {option}
Reset a boolean optionPrefix the option name with no to turn it off.:set no{option}
Toggle a boolean optionFlips the option to the opposite of its current state.:set inv{option}
Give an option a valueFor options that hold a string or a number.:set {option}={value}
Append or add to an optionA string option gets the value appended; a number option is increased by it.:set {option}+={value}
Remove or subtract from an optionA string option loses the value; a number option is decreased by it.:set {option}-={value}
Show the value of an optionWorks for on/off options too, which a bare name would switch on.:set {option}?
Reset an option to its defaultBrings back the value Vim starts with.:set {option}&
Set an option locallyTakes the same arguments as :set but changes only the value local to the buffer or window; :setl for short.:setlocal
Set only the global valueFor options that also have a local value: only the global one is changed; :setg for short.:setglobal
Fix the Delete key codeFull name :fixdel; sets the terminal code 't_kD' to fit the value of 't_kb'.:fix
Open the option windowA window lists the options by function with a one-line explanation each; :opt for short.:options

Quickfix commands 15

ActionShortcut
Show a quickfix errorJumps to error number nr; with no number it shows the current error again.:cc [nr]
Go to next errorMoves to the following entry of the quickfix list; :cn for short.:cnext
Go to previous errorMoves to the entry before the current one; :cp for short.:cprevious
List the errorsPrints the entries of the quickfix list; :cl for short.:clist
Read errors from a fileLoads the file named by 'errorfile' and jumps to the first error; :cf for short.:cfile
Read error file without jumpingFills the list from the error file but leaves the cursor where it is; :cg for short.:cgetfile
Add an error file to the listKeeps the existing entries and puts the new ones after them; :caddf for short.:caddfile
Read errors from a bufferParses the text of a buffer as error messages and jumps to the first; :cb for short.:cbuffer
Read buffer errors without jumpingLike :cbuffer, with the cursor staying put; :cgetb for short.:cgetbuffer
Take errors from an expressionThe result of a Vim expression is parsed as error lines; :cex for short.:cexpr
Expression errors without jumpingLike :cexpr, with the cursor staying put; :cgete for short.:cgetexpr
Add expression errors to the listThe parsed lines join the current quickfix list instead of replacing it; :cadde for short.:caddexpr
Quit with an error codeLeaves Vim without writing, so the compiler or script that started it sees a failure; :cq for short.:cquit
Run make and collect errorsStarts the build program, reads its messages into the quickfix list and goes to the first one.:make [args]
Search files with 'grepprg'Runs the program in 'grepprg' and treats each match as a quickfix entry, jumping to the first.:grep [args]

Various commands 15

ActionShortcut
Redraw the screenWipes the display first and then paints every window again.Ctrl+L
Show file name and cursor positionThe message includes the path of the file.Ctrl+G
Show character codeGives the code of the character at the cursor as decimal, hexadecimal and octal numbers.ga
Show UTF-8 bytes of characterWith UTF-8 encoding, prints in hex the bytes that make up the character at the cursor.g8
Show detailed cursor positionMore detail than Ctrl + G alone: column, line and character position.gthenCtrl+G
Interrupt a searchPressed while Vim is searching, it stops the search.Ctrl+C
Interrupt a search on MS-WindowsThe MS-Windows key for stopping a running search.Ctrl+Break
Remove last digit of a countWhile a count is being typed in Normal mode, takes back the digit entered last.Delete
Show version informationPrints which Vim this is; :ve is the short form.:version
Run Normal-mode commands from ExThe argument is executed as if typed in Normal mode; :norm for short.:normal {commands}
Switch to Ex modeVim then reads one Ex command line after another.Q
Redirect messages to a fileMessages that commands print are also written to the named file from then on.:redir >{file}
Run a command silentlyThe messages the command would normally show are suppressed.:silent {command}
Run a command with confirmationBefore a quit or write would fail on unsaved or read-only files, a dialog asks what to do.:confirm {command}
Pick the file in a dialogA file selection dialog supplies the file name for commands that open, read or write.:browse {command}

Command-line editing 23

ActionShortcut
Abandon the command lineNothing is executed; when 'wildchar' is set to Esc it must be pressed twice.Esc
Enter a character literallyThe next character is taken as it is, even a key that would otherwise act.Ctrl+Vthen{char}
Enter a character by numberUp to three decimal digits give the value of the character to insert.Ctrl+Vthen{number}
Put a register in the command lineThe text of the named register appears at the cursor position.Ctrl+Rthen{register}
Move the cursor one characterArrow keys move within the command being typed.LeftorRight
Move the cursor one wordS- is Vim notation for holding Shift with the arrow key.<S-Left>or<S-Right>
Cursor to start of command lineJumps in front of the first character typed.Ctrl+B
Cursor to end of command lineJumps behind the last character typed.Ctrl+E
Erase character left of cursorTakes away the character just typed, to the left of the cursor.Backspace
Erase character under cursorRemoves the character the cursor is on, keeping the cursor in place.Delete
Erase word left of cursorTakes away the word that was typed last before the cursor.Ctrl+W
Clear the command lineEvery character typed so far is removed and the prompt stays open.Ctrl+U
History filtered by typed textUp brings back an older line and Down a newer one, limited to lines starting with what is typed.UporDown
Step through the whole historyShift with the arrow recalls older or newer lines regardless of what is typed.<S-Up>or<S-Down>
Next match while 'incsearch' is onDuring a / or ? search with 'incsearch' set, moves to the following match without leaving the prompt.Ctrl+G
Previous match while 'incsearch' is onDuring a / or ? search with 'incsearch' set, moves to the match before the current one.Ctrl+T
Show command-line historyPrints the command lines entered earlier; :his for short.:history
Complete what is typedTab is the default 'wildchar': the first match is shown, and further presses cycle through the rest.Tab
Show every matching nameThe candidates are only displayed; nothing is inserted into the command.Ctrl+D
Insert every matching nameAll names that fit the pattern before the cursor are put into the command line.Ctrl+A
Insert the longest common partCompletes as far as all matching names agree and stops there.Ctrl+L
Next completion matchAfter 'wildchar' has found several matches, moves on to the following one.Ctrl+N
Previous completion matchAfter 'wildchar' has found several matches, goes back to the one before.Ctrl+P

Ex ranges 12

ActionShortcut
Separate two line numbersWritten between the first and last line of a range, as in 1,$.,
Separate, moving the cursor firstThe cursor is set to the first line before the second address is worked out.;
Absolute line numberA plain number means that line counted from the top of the file.{number}
Current lineStands for the line the cursor is on..
Last line of the fileOften combined with a first address, as in 1,$.$
Whole fileShorthand for 1,$, every line of the buffer.%
Last Visual areaShorthand for the range between the two Visual marks.*
Line of mark tAn apostrophe and a mark letter give the line where that mark is.'t
Next line matching a patternSearches forward from the current line; the closing slash may be left out at the end./{pattern}[/]
Previous line matching a patternSearches backward from the current line for the address.?{pattern}[?]
Offset downwardsAdded to the address before it, 1 when no number is written.+[num]
Offset upwardsTaken off the address before it, 1 when no number is written.-[num]

Special Ex characters 10

Seven more items are typed literally, each between angle brackets, where a file name is expected: cword and cWORD (the word under the cursor), cfile (the file name under the cursor), sfile (the sourced script), and afile, abuf and amatch inside autocommands.

ActionShortcut
Separate two Ex commandsLets several commands share one line, except after :global and :! which take the bar themselves.|
Begin a commentThe rest of the Ex command line is ignored."
Current file nameIn a place that takes a file name it is replaced by the name of the file being edited.%
Alternate file nameStands for the previously edited file, or with a number for that entry of the buffer list.#[num]
Modifier: full pathAppended to % or # to expand the name to a complete path.:p
Modifier: head of the pathDrops the last component, leaving the directory part.:h
Modifier: tail of the pathKeeps only the file name, without the directories.:t
Modifier: root of the nameStrips the extension from the file name.:r
Modifier: extension onlyLeaves just the extension of the file name.:e
Modifier: substitute in the nameChanges the part of the file name that the pattern matches.:s/{pat}/{repl}/

Starting Vim 5

ActionShortcut
Start with an empty bufferTyped at the shell prompt; options from the startup arguments may follow.vim
Edit one or more filesThe first file is shown and the others wait in the argument list.vim {file} ..
Read text from standard inputThe buffer is filled with what is piped into Vim.vim -
Edit the file holding a tagStarts with the cursor at the definition of the given tag.vim -t {tag}
Start in quickfix modeReads the error file and shows the first error straight away.vim -q [fname]

Startup arguments 31

ActionShortcut
Start the GUIOther options may still follow it on the command line.-g
Open at a line numberPuts the cursor on that line, or on the last line when no number follows the plus.+[num]
Run a command after loadingThe Ex command is executed once the first file has been read.+{command}
Open at a search matchThe cursor starts on the first line where the pattern occurs.+/{pat} {file} ..
Vi modeMakes an ex invocation begin in Normal mode.-v
Ex modeMakes a vim invocation begin in Ex mode instead of Normal mode.-e
Read-only modeGuards against writing by accident and implies -n, so no swap file is made.-R
Forbid modificationsResets the 'write' option, so files cannot be written.-m
Diff modeShows the differences between the files named on the command line.-d
Binary mode-b
Lisp mode-l
Arabic modeStarts with the 'arabic' option set.-A
Hebrew modeStarts with 'hkmap' and 'rightleft' set.-H
Verbose messagesMakes Vim print informative messages while it starts and runs.-V
Compatible modeSets the 'compatible' option so Vim behaves like Vi.-C
Nocompatible modeResets 'compatible', keeping the Vim improvements switched on.-N
List swap filesUsed alone it prints the swap files that could be recovered.-r
Recover a crashed sessionRebuilds the file from its swap file after an edit that was cut short.-r {file} ..
No swap fileSkips the swap file that normally allows recovery.-n
Open several windowsOne window per file unless a number says how many.-o [num]
Keep GUI in the foregroundThe GUI does not fork, so the shell waits until Vim exits.-f
Read commands from a script firstThe characters in the file are executed as if typed before normal editing starts.-s {scriptin}
Record typed characters (append)Everything typed is added to the end of the file.-w {scriptout}
Record typed characters (overwrite)Everything typed is written to the file, replacing what it held.-W {scriptout}
Set the terminal nameTells Vim which terminal type to assume.-T {terminal}
Use another vimrcOnly the named file is read for initialisation; the usual ones are skipped.-u {vimrc}
Use another gvimrcThe same replacement for the file read when the GUI starts.-U {gvimrc}
Use another viminfo fileHistory, marks and registers are read from this file instead of the default one.-i {viminfo}
End of optionsArguments after it are taken as file names even when they begin with a dash.--
Show arguments and exitPrints the list of command-line arguments without starting the editor.--help
Show version and exitPrints the version information without starting the editor.--version

Editing a file 12

The commands that replace the current buffer fail when it has unsaved changes; adding ! to the command name discards those changes instead.

ActionShortcut
Open a file in this windowRefused while the buffer has unsaved changes unless ! is added, which discards them; :e for short.:edit {file}
Reload the current fileReads the file from disk again; with ! any unsaved changes are dropped first.:edit
Start a new unnamed bufferThe window shows an empty buffer with no file name; :ene for short.:enew
Edit a file found in 'path'Searches the directories listed in the 'path' option for the name; :fin for short.:find {file}
Edit the alternate fileWith a count N it edits buffer N, the same as :e #N.Ctrl+^
Edit the file named under cursorTakes the file name at the cursor position and opens that file.gfor]f
Print the current directoryShows which directory relative file names are resolved against.:pwd
Change the current directoryLater file names are taken relative to the new directory.:cd [path]
Return to the previous directoryGoes back to the directory that was current before the last :cd.:cd -
Print file name and positionThe Ex form of Ctrl + G; :f for short.:file
Rename the current bufferGives the buffer a different file name without writing anything yet.:file {name}
List alternate file namesPrints the same list as :buffers.:files

Using the argument list 11

ActionShortcut
Print the argument listThe file being edited is shown in square brackets; :ar for short.:args
One window per argument fileEach file of the argument list gets its own window.:all / :sall
Write and edit the next fileFull name :wnext; saves the current file before moving on in the argument list.:wn
Write to a file, edit the nextSaves under the given name unless that file exists, where ! is needed to overwrite it.:wn {file}
Write and edit the previous fileFull name :wNext; the backward counterpart of :wn.:wN [file]
Edit argument NGoes to the Nth file of the argument list; :sargument N does it in a new window.:argument N
Edit the next argumentMoves one file forward in the argument list; :snext does it in a new window.:next
Replace the argument listThe files given become the new list and the first of them is edited.:next {arglist}
Edit the previous argumentMoves one file back in the argument list; :sNext does it in a new window.:Next
Edit the first argumentJumps to the start of the argument list; :sfirst does it in a new window.:first
Edit the last argumentJumps to the final file of the argument list; :slast does it in a new window.:last

Writing and quitting 17

ActionShortcut
Write the current fileFull name :write; a range in front writes only those lines, and ! forces the write.:w
Write to a named fileRefuses when the file already exists; :w! with the name overwrites it.:w {file}
Append lines to the fileThe buffer, or the range given, is added at the end of the file on disk.:w >>
Append to another fileAdds the lines to the end of the named file instead of replacing it.:w >> {file}
Pipe lines to a commandThe lines become the standard input of the shell command; the buffer itself is not written.:w !{cmd}
Write only if modifiedFull name :update; does nothing when the buffer has no unsaved changes.:up
Write all changed buffersEvery modified buffer is saved in one command; :wa for short.:wall
Quit, unless changes are unsavedFull name :quit; Vim exits when no other non-help buffer is left, and :q! discards the changes.:q
Quit all windowsFull name :qall; stops when a buffer has unsaved changes, which :qa! throws away.:qa
Write the file and quitThe file is written whether or not it was changed; :x skips the write for an unchanged one.:wq
Write to a file and quitSaves under the given name before closing.:wq {file}
Write if changed, then quitUsually typed :x; an unmodified buffer is closed without being written.:xit
Save changes and closeTwo capital Z keys in Normal mode save a changed buffer and close the window.ZZ
Close without savingTwo keys in Normal mode that act as :q! does.ZQ
Save everything and exitEach modified buffer is written and then Vim quits; :xa for short.:xall / :wqall
Suspend VimReturns to the shell with Vim kept in the background; with 'autowrite' set the buffer is saved first unless ! is given.:stop
Suspend VimThe Normal-mode key for :stop.Ctrl+Z

Automatic commands 12

ActionShortcut
Read a viminfo fileLoads saved registers, marks and history; with ! the loaded items replace what is already set.:rviminfo [file]
Write a viminfo fileMerges the current information into the file; with ! the file is written without merging.:wviminfo [file]
Set options from a modelineA line of this form near the top or bottom of a file hands its arguments to :set, subject to the 'modeline' option.vim:{set-arg}:
List all autocommandsFull name :autocmd; with no arguments every defined autocommand is shown.:au
List autocommands for an eventOnly the ones triggered by the named event are shown.:au {event}
List autocommands for a patternNarrows the list to one event and one file pattern.:au {event} {pat}
Add an autocommandThe command will run whenever the event happens for a file matching the pattern.:au {event} {pat} {cmd}
Remove all autocommandsWith nothing after the ! every autocommand is deleted.:au!
Remove autocommands of an eventOnly the named event is cleared; the others keep theirs.:au! {event}
Remove autocommands of a patternThe star stands for all events, so the pattern is cleared everywhere.:au! * {pat}
Remove one event-pattern pairClears just the autocommands registered for that event with that pattern.:au! {event} {pat}
Replace an autocommandRemoves what was defined for the event and pattern, then adds the new command.:au! {event} {pat} {cmd}

Multi-window commands 28

Key caps cannot show letter case, so two commands are not in this table: CTRL-W W (capital W) goes to the window above and wraps around, and CTRL-W R (capital R) rotates the windows upwards.

ActionShortcut
Split the window in twoBoth halves show the same buffer; :split is the Ex form.Ctrl+WthenS
Split and edit a fileOne of the two windows opens the named file.:split {file}
Split vertically and edit a fileThe new window appears beside the current one instead of above it.:vsplit {file}
Make a command split verticallyA prefix: the window the command opens is placed beside the current one.:vertical {cmd}
Split and edit a file from 'path'Looks the name up in the 'path' directories and opens it in a new window; :sf for short.:sfind {file}
Open a terminal windowRuns the command, or a shell when none is given, inside a Vim window.:terminal {cmd}
Split and jump to tagThe tag under the cursor is opened in a new window.Ctrl+Wthen]
Split and edit file under cursorThe file name at the cursor is opened in a new window.Ctrl+WthenF
Split and edit alternate fileThe previously edited file appears in the new window.Ctrl+Wthen^
New empty windowOpens a window on an empty, unnamed buffer; :new is the Ex form.Ctrl+WthenN
Quit the windowEnds editing in this window and closes it; :quit is the Ex form.Ctrl+WthenQ
Close the window, hide the bufferThe buffer stays loaded but hidden; :close is the Ex form.Ctrl+WthenC
Close all other windowsThe current window fills the screen; :only is the Ex form.Ctrl+WthenO
Go to the window belowDoes not wrap around, unlike Ctrl + W followed by Ctrl + W.Ctrl+WthenJ
Go to the window aboveDoes not wrap around when the top window is reached.Ctrl+WthenK
Go to the next window, wrappingMoves down through the windows and continues at the top after the last one.Ctrl+WthenCtrl+W
Go to the top windowJumps straight to the first window on the screen.Ctrl+WthenT
Go to the bottom windowJumps straight to the last window on the screen.Ctrl+WthenB
Go to the previous windowReturns to the window that was active before the current one.Ctrl+WthenP
Rotate windows downwardsEach window moves one place down and the last one comes to the top.Ctrl+WthenR
Exchange with the next windowThe current window and the one after it swap places.Ctrl+WthenX
Make all windows the same sizeEvens out both the height and the width of every window.Ctrl+Wthen=
Decrease window heightThe current window gives up height to its neighbours.Ctrl+Wthen-
Increase window heightThe current window grows taller at the cost of its neighbours.Ctrl+Wthen+
Set window heightWith a count the window gets that many lines; without one it becomes as tall as possible.Ctrl+Wthen_
Decrease window widthNarrows the current window in a vertical split.Ctrl+Wthen<
Increase window widthWidens the current window in a vertical split.Ctrl+Wthen>
Set window widthWith a count the window gets that many columns; without one it becomes as wide as possible.Ctrl+Wthen|

Buffer list commands 12

ActionShortcut
Show the buffer listPrints every buffer Vim knows about together with its file name; :files does the same.:buffers
Open a window per bufferRearranges the screen so that each buffer of the list has a window.:ball / :sball
Open a window per loaded bufferLike :ball, restricted to buffers that are loaded in memory.:unhide / :sunhide
Add a file to the buffer listThe name joins the buffer list without the file being opened in a window.:badd {fname}
Unload a bufferFrees the memory of buffer N while keeping it in the list; ! is needed when it has changes.:bunload [N]
Delete a buffer from the listUnloads buffer N and also removes its entry; ! is needed when it has changes.:bdelete [N]
Go to buffer NShows that buffer in the current window; :sbuffer N does it in a new window.:buffer N
Go to the next bufferA count skips ahead N buffers; :sbnext opens the buffer in a split.:bnext
Go to the previous bufferTwo names for one command; :sbNext and :sbprevious use a new window.:bNext / :bprevious
Go to the first bufferJumps to the start of the buffer list; :sbfirst uses a new window.:bfirst
Go to the last bufferJumps to the end of the buffer list; :sblast uses a new window.:blast
Go to the next modified bufferVisits buffers with unsaved changes; :bmod for short and :sbmod for a split.:bmodified

Syntax highlighting 12

ActionShortcut
Turn on syntax highlightingLoads the syntax files so text is coloured according to its file type.:syntax on
Turn off syntax highlightingStops colouring by syntax in every buffer.:syntax off
Add a syntax keywordThe listed words will be highlighted as members of the syntax group.:syntax keyword {group-name} {keyword} ..
Add a syntax matchText that fits the pattern is assigned to the syntax group.:syntax match {group-name} {pattern} ...
Add a syntax regionDefines a stretch of text between a start and an end pattern.:syntax region {group-name} {pattern} ...
Set how syntax synchronizesArguments such as ccomment or lines {N} tell Vim where to start parsing to get the colours right.:syntax sync
List syntax itemsWith no argument, or with list, the items defined for the buffer are printed.:syntax
Clear all syntax itemsRemoves the syntax definitions of the current buffer.:syntax clear
Reset all highlightingPuts the highlight groups back to their defaults, dropping colours set by the user.:highlight clear
Set highlighting for a groupEach key=arg pair sets one attribute, such as a colour, of the named group.:highlight {group-name} {key}={arg} ..
Turn on file type detectionVim recognises the type of each file opened; this alone does not enable syntax colours.:filetype on
Detection with plugins and indentAlso loads the settings and automatic indenting that belong to each file type.:filetype plugin indent on

GUI commands 9

ActionShortcut
Start the GUIOn Unix this switches a terminal Vim to its graphical version.:gui
Start the GUI and edit filesThe files named are opened once the graphical version has started.:gui {fname} ..
List all menusWith no argument every menu item and its command is printed.:menu
List menus under a pathShows the entries whose menu path starts with the given text.:menu {mpath}
Add a menu itemChoosing the item at that menu path executes the right-hand side.:menu {mpath} {rhs}
Add a menu item with prioritiesThe priorities decide where the item is placed among the others.:menu {pri} {mpath} {rhs}
Add a toolbar buttonItems under the ToolBar menu appear as buttons on the toolbar.:menu ToolBar.{name} {rhs}
Add a tooltip to a menu itemThe text appears when the mouse rests on the item or toolbar button.:tmenu {mpath} {text}
Remove a menuDeletes the item or submenu at the given menu path.:unmenu {mpath}

Folding 20

ActionShortcut
Create folds by handTyped after a colon: folds then exist only where zf or :fold defines them.set foldmethod=manual
Fold by indentationEach stretch of lines sharing a deeper indent becomes a fold.set foldmethod=indent
Fold by expressionThe 'foldexpr' option is evaluated for each line to give its fold level.set foldmethod=expr
Fold by syntax regionsThe syntax file of the language decides which regions can be folded.set foldmethod=syntax
Fold by markersFolds start and end at the marker text defined in 'foldmarker'.set foldmethod=marker
Define a fold over a motionAn operator for manual folding: the lines the motion covers become one fold.zf{motion}
Fold a range of linesThe Ex way to create a manual fold from a line range.:{range}fold
Delete the fold at the cursorRemoves a single level of folding; the text itself is untouched.zd
Delete nested folds at the cursorAll folds at the cursor line are removed, nested ones included.zD
Open one foldReveals the lines of the fold the cursor is on, one nesting level at a time.zo
Open folds at all levelsEvery nested fold on the cursor line is opened in one go.zO
Close one foldCollapses the fold the cursor is in, one nesting level at a time.zc
Close folds at all levelsEvery fold that contains the cursor line is closed.zC
Fold moreLowers 'foldlevel' by one, so one more level of folds closes.zm
Close all foldsDrops 'foldlevel' to zero for the window.zM
Fold lessRaises 'foldlevel' by one, so one more level of folds opens.zr
Open all foldsSets 'foldlevel' to its highest value.zR
Disable foldingResets 'foldenable', so all folds are shown open.zn
Enable foldingSets 'foldenable', bringing the folds back as they were.zN
Toggle foldingInverts 'foldenable', switching all folding on or off.zi

Notes

Motions you stop scrolling for

f{char} and t{char} jump to or just before a character on the line, and ; repeats the jump; with a count they skip ahead. % bounces between matching brackets, } and { move by paragraph, ) and ( by sentence, and [{ and [( go back to the unclosed brace or parenthesis you are inside, which is the fastest way out of a nested block. H, M and L move to the top, middle and bottom of the window without scrolling, while z., z<CR> and z- scroll the window so the current line is centred, top or bottom. gd jumps to the local declaration of the word under the cursor and * searches for it.

Registers, text objects and the dot

Every delete and yank goes to a register; "{char} chooses one — "ayy yanks a line into a, "ap puts it back — and :reg shows them all, which is how you recover text you deleted three edits ago. ]p puts while adjusting indent to the current line. The text objects iw, ip, i', it and their a forms work after any operator, so ci" and di{ are just c{motion} and d{motion} applied to an object. . repeats the last change, q{a-z} records a macro into a register and @{a-z} plays it; & repeats the last substitution on the current line.

Folds, windows and the quickfix list

zf{motion} creates a fold over a motion, zo and zc open and close one, zR and zM open and close all, and zi toggles folding entirely. Windows are on the Ctrl + W prefix: Ctrl + W, S splits, :vsplit {file} splits vertically, Ctrl + W, J and its siblings move between windows, Ctrl + W, O keeps only the current one and Ctrl + W, = equalises sizes; :terminal {cmd} opens a shell in a window. The quickfix list turns compiler output into a navigable list: :make [args] or :grep [args] fills it, :cnext and :cprevious step through errors, :clist shows them all and :cfile loads a saved error file.

How the Ex command rows are written

Each Ex command appears under the name its help tag uses: short for the everyday ones (:w, :q, :wq) and spelled out for the rest (:cnext, :bnext, :ptjump). Where the help prints another accepted spelling, the usage line gives it. Curly braces stand for a part that must be supplied and square brackets for one that may be left out; neither is typed. A range and a trailing ! are left off most rows, and three rows — the two :global forms and :substitute — keep Vim's full bracket notation because the pattern follows the command name directly.

Questions

What do the braces and square brackets in the commands mean?

Curly braces mark a part you must supply: f{char} takes a character and d{motion} a motion. Square brackets mark an optional part, as in :cc [nr]. Neither kind of bracket is typed.

Which key is CR in Vim's notation?

The Enter key. z<CR> is z followed by Enter, and /<CR> repeats the last search. In Insert mode Ctrl + M and Ctrl + J begin a new line just as Enter does.

Why are CTRL-W W and CTRL-W R missing from the window commands?

Both need a capital letter after CTRL-W, and the key-cap notation used for chords on this page cannot show letter case. CTRL-W W goes to the window above and wraps around; CTRL-W R rotates the windows upwards. Their lowercase counterparts are in the table.

How do I recover something I deleted a while ago?

Deleted text rotates through registers 1 to 9. :reg shows them; "3p puts the third most recent deletion.

How do I use the quickfix list without make?

Run :grep pattern files (or :vimgrep), then :cnext and :cprevious to move between matches and :clist to print the list (:copen shows it in a window).

How do I close every fold except the one I am in?

zM closes all folds, then zv or zo opens the one at the cursor. zR reopens everything.

Sources and checks

Every row on this page was matched to a line in the documentation above on . A binding that could not be found there is not listed.

9 rows from the earlier version of this page were removed in that check: duplicates, and bindings the documentation does not list or lists differently.

Found a wrong or missing key? Tell us and it gets checked against the source. How we verify describes the process and its limits.