Modes and escaping 14
| Action | Shortcut |
|---|---|
| Insert before cursorStarts Insert mode at the cursor; a count repeats the typed text that many times. | i |
| Append after cursorStarts Insert mode one position to the right of the cursor. | a |
| Insert at line startStarts typing in front of the first non-blank character of the line. | I |
| Append at line endJumps to the end of the line and starts Insert mode there. | A |
| Open line belowAdds an empty line under the current one and starts Insert mode on it. | o |
| Open line aboveAdds an empty line over the current one and starts Insert mode on it. | O |
| Insert where typing last stoppedMoves to the mark Vim keeps for the last insert position, then starts Insert mode. | gi |
| Return to Normal modeEnds Insert mode; in Visual mode it drops the selection and on the command line it cancels the command. | Esc |
| Leave Insert modeDoes exactly what the Esc key does when typing in Insert mode. | Ctrl+[ |
| Start Visual modeSelects character by character as the cursor moves; an operator then acts on the selection. | v |
| Start linewise Visual modeSelects whole lines regardless of the cursor column. | V |
| Start blockwise Visual modeSelects a rectangle of columns that spans several lines. | Ctrl+V |
| Enter Replace modeEach typed character overwrites an existing one until Esc is pressed. | R |
| Start an Ex commandOpens the command line at the bottom of the screen, where commands like :w are typed. | : |
Moving the cursor 26
Most commands accept a count typed in front of them; the quick reference marks those commands with N.
| Action | Shortcut |
|---|---|
| Move leftBackspace and the Left arrow do the same; a count moves that many characters. | h |
| Move downA count in front moves that many lines; the Down arrow does the same. | j |
| Move upA count in front moves that many lines; the Up arrow does the same. | k |
| Move rightSpace and the Right arrow do the same in Normal mode. | l |
| Forward one wordLands at the start of the next word; a count skips several words. | w |
| Back one wordLands at the start of the previous word; a count skips several words. | b |
| End of wordStops on the last character of the word rather than on the first of the next. | e |
| Forward one WORDA WORD is anything between blanks, so punctuation does not stop the motion. | W |
| Back one WORDLike b, but only white space separates the items it jumps over. | B |
| Start of lineGoes to column one even when the line is indented; Home does the same. | 0 |
| First non-blank characterSkips leading spaces and tabs, landing where the text of the line begins. | ^ |
| End of lineWith a count it finishes on a lower line: 2$ is the end of the next line. | $ |
| Go to first linePreceded by a number it jumps to that line instead. | gg |
| Go to last linePreceded by a number it jumps to that line instead of the final one. | G |
| Find character forwardMoves onto the next place the typed character appears, to the right of the cursor. | f{char} |
| Find character backwardLooks left from the cursor for the typed character and lands on it. | F{char} |
| Jump just before a characterStops one position short of the match on the right. | t{char} |
| Jump back just after a characterSearches leftwards and stops one position after the match. | T{char} |
| Repeat character searchRuns the previous f, F, t or T again in the same direction. | ; |
| Repeat character search reversedRuns the previous f, F, t or T again the other way. | , |
| Next paragraphA count moves that many paragraphs toward the end of the file. | } |
| Previous paragraphA count moves that many paragraphs toward the start of the file. | { |
| Jump to matching bracketFinds the next bracket or brace on the line and moves to its partner. | % |
| Top line of windowMoves the cursor, not the text, to the first line shown on screen. | H |
| Middle line of windowPuts the cursor halfway down the visible part of the file. | M |
| Bottom line of windowMoves the cursor to the last line shown, or with a count to that line counted from the bottom. | L |
Scrolling 7
| Action | Shortcut |
|---|---|
| Scroll forward one pageShows the next screenful of the file; a count scrolls several pages. | Ctrl+F |
| Scroll back one pageShows the previous screenful of the file. | Ctrl+B |
| Scroll down half a pageHalf a window by default; a count sets the number of lines instead. | Ctrl+D |
| Scroll up half a pageHalf a window by default, toward the start of the file. | Ctrl+U |
| Center cursor lineRedraws so the line with the cursor sits in the middle of the window. | zz |
| Cursor line to topRedraws with the line holding the cursor as the first one shown. | zt |
| Cursor line to bottomRedraws with the line holding the cursor as the last one shown. | zb |
Editing text 16
| Action | Shortcut |
|---|---|
| Delete character under cursorA count removes that many characters to the right. | x |
| Delete character before cursorRemoves the character on the left; the manual gives it as short for dh. | X |
| Replace one characterOverwrites what is under the cursor with the typed character and stays in Normal mode. | r{char} |
| Substitute characterDeletes the character under the cursor and starts Insert mode. | s |
| Change whole lineRemoves the text of the line and starts Insert mode in its place. | cc |
| Change to end of lineDeletes from the cursor rightwards and starts Insert mode. | C |
| Delete to end of lineRemoves everything from the cursor rightwards; the manual gives it as short for d$. | D |
| Delete lineThe line goes into a register, so p can put it back somewhere else. | dd |
| Join linesPulls the next line up onto the current one, with a space between them. | J |
| Toggle caseFlips the case of the character under the cursor and moves right. | ~ |
| Indent lineShifts the line right by the 'shiftwidth' setting; a count indents several lines. | >> |
| Unindent lineShifts the line left by the 'shiftwidth' setting. | << |
| Reindent lineCorrects the indentation of the line with Vim's indenting or the program in 'equalprg'. | == |
| Increment numberWorks on the number under the cursor or the next one after it; a count adds that amount. | Ctrl+A |
| Decrement numberLowers the number under the cursor or the next one after it. | Ctrl+X |
| Swap two charactersA combination of x and p: the deleted character is put back after its neighbour. | xp |
Insert mode keys 5
| Action | Shortcut |
|---|---|
| Run one Normal-mode commandExecutes a single command from Insert mode, then continues inserting. | Ctrl+O |
| Delete word before cursorWorks while typing in Insert mode, without leaving it. | Ctrl+W |
| Delete text typed on the lineRemoves everything entered on the current line during this insert. | Ctrl+U |
| Complete word (next match)Offers the next word in the text that starts with what is typed before the cursor. | Ctrl+N |
| Insert text from a registerPastes without leaving Insert mode; follow the chord with the register name. | Ctrl+Rthen{register} |
Operators 11
| Action | Shortcut |
|---|---|
| Delete over a motionAn operator: follow it with any motion or text object to say what to remove. | d{motion} |
| Change over a motionDeletes like d and then starts Insert mode for the replacement. | c{motion} |
| Yank over a motionCopies without altering the buffer; p or P puts the copy back. | y{motion} |
| Indent over a motionShifts every line the motion covers right by one 'shiftwidth'. | >{motion} |
| Reindent over a motionCorrects the indentation of all lines the motion covers. | ={motion} |
| Lowercase over a motionTurns capitals into small letters across the text the motion covers. | gu{motion} |
| Uppercase over a motionTurns small letters into capitals across the text the motion covers. | gU{motion} |
| Format lines to text widthRewraps the covered lines so none is longer than the 'textwidth' option. | gq{motion} |
| Delete to next wordThe d operator with the w motion; 3dw or d3w removes three words. | dw |
| Change wordDeletes a word and then starts Insert mode for its replacement. | cw |
| Yank wordCopies from the cursor up to the next word into a register. | yw |
Text objects 14
Text objects work only after an operator or in Visual mode; typed alone in Normal mode the same letters are other commands.
| Action | Shortcut |
|---|---|
| Inner wordAfter an operator or in Visual mode: the word under the cursor without the space around it. | iw |
| A wordThe word plus the white space beside it, wherever the cursor is inside the word. | aw |
| Inner paragraphAll lines of the paragraph the cursor is in, without the blank lines after it. | ip |
| A paragraphThe paragraph together with the blank lines that follow it. | ap |
| Inner parentheses blockThe text between a pair of round brackets, also typed as i( or i). | ib |
| Inner braces blockThe text between a pair of curly braces, also typed as i{ or i}. | iB |
| Inner tag blockThe content between an opening HTML or XML tag and its closing tag. | it |
| Inner double-quoted stringThe text between two double quotes, leaving the quote marks out. | i" |
| A double-quoted stringThe quoted text including both quote marks. | a" |
| Delete inner wordRemoves the word under the cursor but leaves the surrounding white space. | diw |
| Delete a wordRemoves the word under the cursor together with the white space next to it. | daw |
| Change inner wordWorks from any position inside the word and starts Insert mode for the new text. | ciw |
| Delete inside parenthesesEmpties the bracket pair around the cursor and keeps the brackets; dib is the same. | di( |
| Delete inner paragraphThe cursor can be on any line of the paragraph. | dip |
Copy, paste and registers 8
On X11 the "* register is the primary selection (pasted with a middle click) and "+ is the clipboard.
| Action | Shortcut |
|---|---|
| Yank lineCopies the whole current line; a count copies that many lines. | yy |
| Put after cursorPastes the last yanked or deleted text; whole lines go below the current line. | p |
| Put before cursorPastes in front of the cursor, or above the current line for whole lines. | P |
| Use a named registerA prefix for the next yank, delete or put that names where the text is stored or taken from. | "{register} |
| Yank to system clipboardNeeds a Vim built with clipboard support; follow it with a motion or use it in Visual mode. | "+y |
| Paste from system clipboardPuts what another application copied after the cursor. | "+p |
| Discard into black hole registerText deleted or yanked into it is thrown away, so the other registers keep their contents. | "_ |
| List registersShows what every register currently holds. | :reg |
Search and replace 12
| Action | Shortcut |
|---|---|
| Search forwardType the pattern and press Enter; the cursor jumps to the next match. | /{pattern} |
| Search backwardType the pattern and press Enter; the cursor jumps to the match before it. | ?{pattern} |
| Next matchRepeats the last / or ? search in the direction it was made. | n |
| Previous matchRuns the last search again the other way round. | N |
| Search word under cursorLooks ahead for whole-word matches of the identifier the cursor is on. | * |
| Search word under cursor backwardThe same lookup as the star key, going toward the start of the file. | # |
| Clear search highlightingShort for :nohlsearch; switches the 'hlsearch' highlight off until the next search. | :noh |
| Replace on current lineChanges every old to new on the cursor line; without the g flag only the first one. | :s/old/new/g |
| Replace in whole fileThe percent sign makes the range the entire file instead of one line. | :%s/old/new/g |
| Replace with confirmationStops at each match and asks before substituting it. | :%s/old/new/gc |
| Highlight all matchesMarks every match of the search pattern, not only the one the cursor jumped to. | :set hlsearch |
| Ignore case in searchesMakes patterns match upper and lower case alike; :set noignorecase reverses it. | :set ignorecase |
Visual mode 12
| Action | Shortcut |
|---|---|
| Go to other end of selectionLets the selection be extended from its opposite end without starting over. | o |
| Reselect previous selectionTyped in Normal mode, it restores the area that was selected last time. | gv |
| Delete selectionRemoves everything that is highlighted in one step. | d |
| Yank selectionCopies the selected text into a register. | y |
| Change selectionDeletes the selected text and starts Insert mode for its replacement. | c |
| Indent selectionMoves the selected lines right by one 'shiftwidth'. | > |
| Join selected linesMerges everything highlighted into a single line, as J does for two lines in Normal mode. | J |
| Make selection lowercaseIn Visual mode this key changes case; it does not undo. | u |
| Make selection uppercaseTurns every letter in the selected area into a capital. | U |
| Insert before blockBlockwise selection only: what is typed appears at the left edge of every selected line. | I |
| Append after blockBlockwise selection only: what is typed is added at the right edge of every selected line. | A |
| Run Ex command on selectionThe command line opens with the selected lines already filled in as the range. | : |
Undo, repeat and macros 9
| Action | Shortcut |
|---|---|
| Undo last changeEach press goes one change further back; a count undoes several at once. | u |
| Redo undone changeReverses the effect of u, step by step or by a count. | Ctrl+R |
| Undo all changes on lineTakes the line edited last back to how it was before the recent changes to it. | U |
| Repeat last changeReplays the previous edit at the new cursor position; a count replaces the original count. | . |
| Repeat last Ex commandRuns again the most recent command entered on the : line. | @: |
| Record a macroEverything typed afterwards is stored in the chosen register until q is pressed again. | q{a-z} |
| Stop recordingEnds the recording started with q and a register letter. | q |
| Run a macroPlays back the keystrokes stored in that register; a count plays them several times. | @{a-z} |
| Repeat last macroRuns again whichever register was executed most recently. | @@ |
Files and buffers 22
| Action | Shortcut |
|---|---|
| Save the fileWrites the buffer to its file and keeps it open for editing. | :w |
| Write to another fileFails when that file is already there; add ! after :w to overwrite it. | :w {file} |
| Save all buffersWrites every buffer that has unsaved changes in one go. | :wa |
| Quit current windowRefuses while there are unsaved changes; closing the last window exits Vim. | :q |
| Quit without savingThrows away every change made since the last write. | :q! |
| Save and quitAlways writes the file, even when nothing was changed, then closes the window. | :wq |
| Save if changed, then quitLike :wq, except that an unmodified file is not written again. | :x |
| Save if changed and quitThe Normal-mode way to do :x, typed without the command line. | ZZ |
| Quit and discard changesThe Normal-mode way to do :q!, typed without the command line. | ZQ |
| Exit VimCloses every window at once, but stops if any buffer has unsaved changes. | :qa |
| Edit a fileOpens the named file in the current window; it fails while the buffer has unsaved changes. | :e {file} |
| Reload file, discarding changesGoes back to the version on disk and keeps Vim running. | :e! |
| Insert a file below cursorReads the named file into the buffer under the current line. | :r [file] |
| Run a shell commandThe text after the exclamation mark is handed to the shell as typed. | :!{command} |
| Show file name and positionPrints a status message with the path of the file and where the cursor is in it. | Ctrl+G |
| Open file under cursorTreats the text at the cursor as a file name and edits that file. | gf |
| List buffersPrints all buffers of the session with their file names. | :ls |
| Go to buffer by numberN is the number shown by :ls. | :b N |
| Go to next bufferShort for :bnext; a count in front skips that many buffers. | :bn |
| Go to previous bufferShort for :bprevious, the opposite direction through the buffer list. | :bp |
| Close a bufferUnloads the buffer from memory and takes it off the list. | :bd |
| Switch to alternate fileFlips between the current file and the one edited before it. | Ctrl+^ |
Windows and tabs 18
Key caps cannot show letter case, so Ctrl-W commands that take a capital letter are not in this table; in Vim, CTRL-W T (with Shift held for the T) moves the current window to a new tab page.
| Action | Shortcut |
|---|---|
| Split window horizontallyDivides the current window in two; the command form of the Ctrl-W s key. | :sp |
| Split window verticallyPuts the two windows side by side instead of one over the other. | :vsp |
| Split current windowA count typed first sets how many lines high the new window is. | Ctrl+WthenS |
| Split current window verticallyOpens the new window beside the current one. | Ctrl+WthenV |
| Go to next windowCycles through the windows and wraps round to the first after the last. | Ctrl+WthenW |
| Go to window on the leftStops at the leftmost window instead of wrapping. | Ctrl+WthenH |
| Go to window belowStops at the lowest window instead of wrapping. | Ctrl+WthenJ |
| Go to window aboveStops at the topmost window instead of wrapping. | Ctrl+WthenK |
| Go to window on the rightStops at the rightmost window instead of wrapping. | Ctrl+WthenL |
| Close windowWorks like :close: the window goes away and its buffer stays available. | Ctrl+WthenC |
| Quit windowWorks like :q, so on the last window it exits Vim. | Ctrl+WthenQ |
| Keep only this windowCloses every other window on the screen; :only is the command form. | Ctrl+WthenO |
| Equalize window sizesGives all windows the same height and width. | Ctrl+Wthen= |
| Open a new tab pageGiven a file name, it edits that file in the new tab page. | :tabnew |
| Go to next tab | gt |
| Go to previous tab | gT |
| Close tab pageCloses the tab page that is currently shown. | :tabclose |
| Close all other tabsLeaves the current tab page as the only one open. | :tabonly |
Marks and jumps 10
| Action | Shortcut |
|---|---|
| Set a markLowercase marks belong to one file; a capital letter can be jumped to from any file. | m{a-zA-Z} |
| Jump to a markReturns to the exact line and column where the mark was set. | `{a-zA-Z0-9} |
| Jump to the line of a markLands on the first non-blank character of the marked line, not on the exact column. | '{a-zA-Z0-9} |
| Return to position before jumpTyped twice, it goes forth again, so it toggles between two places. | `` |
| Jump to last changeGoes to the place in this file where text was edited most recently. | `. |
| List marksPrints the marks that are currently set. | :marks |
| Go back in jump listSteps back through the places earlier jumps started from. | Ctrl+O |
| Go forward in jump listReverses a step back through the jump list; Tab sends the same key code. | Ctrl+I |
| Jump to tag under cursorFollows the identifier or help link under the cursor to its definition. | Ctrl+] |
| Return from tag jumpGoes back to where the last tag jump was made from. | Ctrl+T |
Folding 7
| Action | Shortcut |
|---|---|
| Create a foldAn operator: the motion after it decides which lines are folded away. | zf{motion} |
| Open foldOpens a single level of folding at the cursor line. | zo |
| Close foldCloses a single level of folding at the cursor line. | zc |
| Toggle foldOpens the fold at the cursor when it is closed and closes it when it is open. | za |
| Open every foldRaises 'foldlevel' to its maximum so nothing in the buffer stays folded. | zR |
| Close every foldSets 'foldlevel' to zero so each fold in the buffer collapses. | zM |
| Delete foldRemoves the fold definition at the cursor; the text itself stays. | zd |
Command line and help 11
| Action | Shortcut |
|---|---|
| Recall matching history entryShows only earlier command lines that begin with what is already typed. | UporDown |
| Complete on the command lineCompletes what is typed before the cursor; pressing it again shows the next match. | Tab |
| List possible completionsPrints every name that fits what has been typed so far. | Ctrl+D |
| Paste a register into the commandInserts the register text at the cursor position of the command line. | Ctrl+Rthen{register} |
| Open command-line windowOpens a window holding the : history, where a command can be edited like text. | q: |
| Open the help windowOpens the general help page in its own window. | :help |
| Get help on a subjectAccepts a command, key or option name, such as :help x or :help CTRL-A. | :help {subject} |
| Look up word under cursorPasses the word to the program in 'keywordprg', which is man by default. | K |
| Switch an option onFor on/off options; for options with a value it shows the current value. | :set {option} |
| Switch an option offThe no prefix resets an on/off option, as in :set nonumber. | :set no{option} |
| Show line numbersDisplays the number of each line in front of it. | :set number |
No row on this page matches that filter.
Notes
Operators, motions and counts
dd deletes a line and dw deletes a word because d is an operator and w is a motion; the same operator with $ deletes to the end of the line, which is exactly what D is a shortcut for. Any motion in the Moving the cursor group can follow d{motion}, y{motion} (yank) or c{motion} (change), and a number in front repeats: 3dw deletes three words, 5j moves down five lines. Once this clicks, the table stops being a list to memorise and becomes a few operators times a few motions.
Text objects are the part worth learning early
ciw changes the word under the cursor and diw deletes it, from anywhere inside the word — you do not need to move to its start first. The same pattern works with quotes (i"), parentheses (ib), braces (iB) and tags (it), and with a instead of i to include the delimiters: c followed by i" replaces the text inside a pair of double quotes on the line. Text objects are only valid after an operator or in Visual mode, which is why iw typed on its own just starts Insert mode.
The dot command and macros
. repeats the last change, including an insert, so the workflow for a repeated edit is: make the change once, move to the next place with n or a motion, press dot. For anything longer, q{a-z} starts recording a macro into a register (qa uses register a), q stops, and @{a-z} replays it; a count in front replays it that many times. u undoes and Ctrl + R redoes — note that Ctrl + R inside Insert mode is a different command that pastes a register.
Getting out, and the modes that confuse beginners
:wq saves and quits, :q! quits and discards changes, and Esc returns to Normal mode from anywhere; if the editor seems to ignore you, press Esc first. v, V and Ctrl + V start character, line and block visual selections, and block mode plus I is how you prepend text to many lines at once. R enters Replace mode, which overwrites rather than inserts and is the usual cause of "my text is disappearing as I type".
Questions
What is the difference between dw and D?
dw deletes from the cursor to the start of the next word. D deletes from the cursor to the end of the line and is shorthand for d$.
Do these commands work in Neovim and VS Code's Vim extension?
Neovim keeps Vim's default bindings. The Vim modes of VS Code, JetBrains IDEs and Obsidian implement the core operators, motions and text objects; how much of the Ex command line, folding and window commands they cover differs from one to the next.
Why is my text being overwritten as I type?
You are in Replace mode, entered with R. Press Esc, then i or a to insert normally.
How do I repeat an edit on many lines?
Make the change once, then use . to repeat it after each motion. For multi-step edits record a macro with qa … q and replay it with @a, optionally with a count.
How do I quit Vim without saving?
Press Esc to make sure you are in Normal mode, type :q! and press Enter. Vim quits without writing the file, so every unsaved change in the buffer is lost.
Plain :q refuses to quit a modified buffer and shows error E37, "No write since last change"; :wq writes the file first and then quits. Typing ZQ in Normal mode is the same as :q! without the command line. With several files open, :qa! exits Vim and discards the changes in all of them.
Sources and checks
- Vim help: quickref.txt, the quick reference guide (Vim 9.2, tag v9.2.1169) Most Normal, Insert, Visual and command-line rows
- Vim help: index.txt, the index of all commands (Vim 9.2, tag v9.2.1169) Window commands, tab pages, g and z commands, text object names, Ex command names
- Vim user manual: usr_02.txt, The first steps in Vim (Vim 9.2, tag v9.2.1169) Reloading a file and the :help commands
- Vim user manual: usr_03.txt, Moving around (Vim 9.2, tag v9.2.1169) The :set examples for line numbers and searching
- Vim user manual: usr_04.txt, Making small changes (Vim 9.2, tag v9.2.1169) Operator and motion combinations such as dw, diw, daw and xp
- Vim tutor, chapter 1 (runtime/tutor/tutor1, Vim 9.2, tag v9.2.1169) Substitute command lines, :q! and yw
- Vim tutor, chapter 2 (runtime/tutor/tutor2, Vim 9.2, tag v9.2.1169) Text object combinations and the clipboard and black hole registers
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.
2 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.