VIM Cheatsheet

CommandDescription
,Repeats the previous f, t, F, or T cursor movement command in the opposite direction.
;Repeats the previous f, t, F, or T cursor movement command in the same direction.
:%s/old/new/gReplaces all occurrences of 'old' with 'new' throughout the entire file.
:%s/old/new/gcReplaces all occurrences of 'old' with 'new' throughout the entire file, prompting for confirmation before each replacement.
:3,5dDeletes lines 3 through 5.
:b[uffer] fileSwitches to the buffer associated with the specified file name.
:b[uffer]#Switches to the buffer identified by its index number.
:bd[elete]Deletes a specified buffer, which effectively closes the associated file.
:bn[ext]Switches to the next buffer.
:bp[revious]Switches to the previous buffer.
:ccl[ose]Closes the quickfix window, which contains the list of search results.
:changesDisplays a list of all recent changes made in the buffer.
:clo[se]Closes the current pane in Vim.
:cn[ext]Jumps to the next match from a previous search.
:cope[n]Opens a window that displays a list of matches from the previous search.
:cp[revious]Jumps to the previous match from a previous search.
:dif[fupdate]Updates the displayed differences between buffers in diff mode.
:diffo[ff]Disables diff mode for the current window.
:diffthisMarks the current window as part of the diff comparison.
:e[dit] fileOpens a specified file for editing in a new buffer.
:h[elp] keywordOpens the help page for the specified keyword in Vim.
:ju[mps]Displays a list of all recent jumps.
:ls or :buffersDisplays a list of all currently open buffers.
:marksDisplays a list of all saved marks.
:noh[lsearch]Removes the highlighting of search matches.
:qExits Vim. Fails if there are unsaved changes.
:q! or ZQExits Vim and discards any unsaved changes.
:reg[isters]Displays the contents of all registers.
:sav[eas] fileSaves the current file with the specified file name.
:sp[lit] fileOpens a specified file in a new buffer and splits the window horizontally to display it.
:tab ba[ll]Opens all open buffers in separate tabs.
:tabc[lose]Closes the current tab and all its associated windows.
:tabdo commandRuns the specified command on all open tabs.
:tabm[ove] #Moves the current tab to the position specified by the number # (indexed from 0).
:tabnew or :tabnew {page.words.file}Opens a new tab, optionally with a specified file.
:tabo[nly]Closes all tabs except the currently active tab.
:ter[minal]Opens a terminal window within Vim.
:vert[ical] ba[ll]Arranges all open buffers as vertical windows.
:vim[grep] /pattern/ {`{file}`}Searches for a given pattern in multiple files.
:vs[plit] fileOpens a specified file in a new buffer and splits the window vertically to display it.
:wSaves the current file without exiting Vim.
:w !sudo tee %Saves the current file using sudo (superuser privileges). This is useful when you don't have write permissions to the file.
:wq or :x or ZZSaves the current file and exits Vim.
:wqaSaves all open files and exits Vim.
?patternSearches backward for the specified pattern.
.Repeats the last executed command.
'"Moves the cursor to the position when you last edited this file.
"+pPastes the contents of the system clipboard.
"+yCopies (yanks) the selected text into the system clipboard.
"xpPastes the contents of the specified register x.
"xyCopies (yanks) the selected text into the specified register x.
[cJumps to the start of the previous change in the document.
]cJumps to the start of the next change in the document.
]pPastes the contents of the default register (") and adjusts the indentation to match the current line.
{Moves the cursor to the beginning of the previous paragraph. When editing code, it moves to the previous function or block.
}Moves the cursor to the beginning of the next paragraph. When editing code, it moves to the next function or block.
@@Repeats the last executed macro.
@aExecutes the macro stored in register 'a'.
/patternSearches forward for the specified pattern.
\vpatternSearches for the specified pattern using 'very magic' mode, where non-alphanumeric characters are interpreted as special regex symbols without escaping.
#gtMoves to the tab specified by the number #.
%Moves the cursor to the matching character of a pair, such as parentheses, brackets, or braces. Use :h matchpairs in Vim for more information on supported pairs.
`.`Moves the cursor to the position of the last change in this file.
``Moves the cursor to the position before the last jump.
`0Moves the cursor to the position where Vim was last exited.
`aMoves the cursor to the position marked as A.
^Moves the cursor to the first non-blank character on the current line.
<In visual mode, shifts the selected text one indentation level to the left.
<%De-indents a block enclosed by parentheses () or curly brackets {}, with the cursor positioned on the opening or closing brace.
<<De-indents the current line one shiftwidth to the left.
=%Re-indents a block enclosed by parentheses () or curly brackets {}, with the cursor positioned on the opening or closing brace.
=iBRe-indents the inner block enclosed by curly brackets {}.
>In visual mode, shifts the selected text one indentation level to the right.
>%Indents a block enclosed by parentheses () or curly brackets {}, with the cursor positioned on the opening or closing brace.
>>Indents the current line one shiftwidth to the right.
>atIndents a block enclosed by angle brackets <> (tags).
>ibIndents the inner block enclosed by parentheses ().
~In visual mode, switches the case (uppercase/lowercase) of the selected text.
$Moves the cursor to the end of the current line.
0Moves the cursor to the very beginning of the current line.
2ddDeletes the current line and the next line and places them in the default register (").
2yyCopies the current line and the next line into the default register (").
3==Re-indents the current line and the two lines below it.
5gg or 5GMoves the cursor to line number 5 in the document.
aEnters insert mode and starts inserting text after the cursor position.
AEnters insert mode and starts inserting text at the end of the current line.
abIn visual mode, selects a block of text enclosed by parentheses ().
aBIn visual mode, selects a block of text enclosed by curly braces {}.
atIn visual mode, selects a block of text enclosed by angle brackets <> (often used for tags).
awIn visual mode, selects the current word.
bMoves the cursor backward to the beginning of the previous word.
BMoves the cursor backward to the beginning of the previous word, considering punctuation as part of the word.
c$ or CReplaces text from the cursor position to the end of the current line.
ccReplaces the content of the entire current line.
ciwReplaces the entire word under the cursor.
Ctrl + ]Jumps to the definition of the tag under the cursor.
Ctrl + bScrolls the screen up one page and moves the cursor to the last line of the new page.
Ctrl + dScrolls the screen down half a page and moves the cursor accordingly.
Ctrl + dDe-indents the current line one shiftwidth to the left while in insert mode.
Ctrl + eScrolls the screen down one line without moving the cursor.
Ctrl + fScrolls the screen down one page and moves the cursor to the first line of the new page.
Ctrl + hDeletes the character before the cursor while in insert mode.
Ctrl + iMoves the cursor to the next newer position in the jump list.
Ctrl + jInserts a line break at the current cursor position while in insert mode.
Ctrl + nInserts the next matching completion before the cursor while in insert mode.
Ctrl + oMoves the cursor to the next older position in the jump list.
Ctrl + oxTemporarily switches to normal mode from insert mode to execute a single normal mode command 'x'. After executing the command, it returns to insert mode.
Ctrl + pInserts the previous matching completion before the cursor while in insert mode.
Ctrl + rRedoes a previously undone change.
Ctrl + rxInserts the contents of register 'x' at the cursor position.
Ctrl + tIndents the current line one shiftwidth to the right while in insert mode.
Ctrl + uScrolls the screen up half a page and moves the cursor accordingly.
Ctrl + vStarts visual block mode, allowing you to select a rectangular block of text.
Ctrl + wDeletes the word before the cursor while in insert mode.
Ctrl + w=Resizes all windows in the current split arrangement to have equal height and width.
Ctrl + whMoves the cursor to the window located to the left in a vertical split arrangement.
Ctrl + wHMakes the current window occupy the full height of the screen and positions it as the leftmost window in a vertical split arrangement.
Ctrl + wjMoves the cursor to the window located below in a horizontal split arrangement.
Ctrl + wJMakes the current window occupy the full width of the screen and positions it as the bottommost window in a horizontal split arrangement.
Ctrl + wkMoves the cursor to the window located above in a horizontal split arrangement.
Ctrl + wKMakes the current window occupy the full width of the screen and positions it as the topmost window in a horizontal split arrangement.
Ctrl + wlMoves the cursor to the window located to the right in a vertical split arrangement.
Ctrl + wLMakes the current window occupy the full height of the screen and positions it as the rightmost window in a vertical split arrangement.
Ctrl + wqCloses the currently active window within a split arrangement.
Ctrl + wsSplits the current window horizontally, creating a new split.
Ctrl + wTMoves the currently active split window into its own new tab.
Ctrl + wvSplits the current window vertically, creating a new split.
Ctrl + wwSwitches the focus to the next window within the current split arrangement.
Ctrl + wxExchanges the position of the current window with the next one in the split arrangement.
Ctrl + yScrolls the screen up one line without moving the cursor.
cw or ceReplaces text from the cursor position to the end of the current word.
dIn visual mode, deletes the selected text.
d$ or DDeletes the characters from the cursor position to the end of the line and places them in the default register (").
dawDeletes the word under the cursor and the space after or before it and places it in the default register (").
ddDeletes the current line and places it in the default register (").
diwDeletes the word under the cursor and places it in the default register (").
do or :diffg[et]Obtains (gets) the difference from another buffer and applies it to the current buffer.
dp or :diffpu[t]Puts (applies) the difference from the current buffer to another buffer.
dwDeletes the characters of the word from the cursor position to the start of the next word and places them in the default register (").
eMoves the cursor forward to the end of the current word.
EMoves the cursor forward to the end of the current word, considering punctuation as part of the word.
eaMoves the cursor to the end of the current word and enters insert mode.
Esc or Ctrl + cExits insert mode and returns to normal mode.
Esc or Ctrl + cExits visual mode.
fxMoves the cursor to the next occurrence of character 'x' on the current line.
FxMoves the cursor to the previous occurrence of character 'x' on the current line.
GMoves the cursor to the last line of the document.
g_Moves the cursor to the last non-blank character on the current line.
g,Moves the cursor to the next newer position in the change list.
g;Moves the cursor to the next older position in the change list.
g~Switches the case of characters (uppercase to lowercase or vice versa) from the cursor position to the end of the specified motion.
gdMoves the cursor to the local declaration of the variable under the cursor (useful for code editing).
gDMoves the cursor to the global declaration of the variable under the cursor (useful for code editing).
geMoves the cursor backward to the end of the previous word.
gEMoves the cursor backward to the end of the previous word, considering punctuation as part of the word.
ggMoves the cursor to the first line of the document.
gg=GRe-indents the entire buffer (all lines in the current file).
gjMoves the cursor down one line, considering wrapped lines as a single line.
gJJoins the line below the current line to the end of the current line without adding any space.
gkMoves the cursor up one line, considering wrapped lines as a single line.
gpPastes the contents of the default register (") after the cursor and leaves the cursor after the new text.
gPPastes the contents of the default register (") before the cursor and leaves the cursor after the new text.
gt or :tabn[ext]Navigates to the next tab.
gT or :tabp[revious]Navigates to the previous tab.
guChanges the characters from the cursor position to the end of the specified motion to lowercase.
gUChanges text to uppercase up to the specified motion.
gwipReflows the current paragraph, adjusting line breaks to fit within the current window width.
hMoves the cursor one character to the left.
HMoves the cursor to the top of the screen.
iEnters insert mode and starts inserting text before the cursor position.
IEnters insert mode and starts inserting text at the beginning of the current line.
ibIn visual mode, selects the text within the nearest enclosing parentheses ().
iBIn visual mode, selects the text within the nearest enclosing curly braces {}.
itIn visual mode, selects the text within the nearest enclosing angle brackets <> (often used for tags).
jMoves the cursor one line down.
JJoins the line below the current line to the end of the current line, adding a single space in between.
kMoves the cursor one line up.
KOpens the man page for the word currently under the cursor.
lMoves the cursor one character to the right.
LMoves the cursor to the bottom of the screen.
MMoves the cursor to the middle of the screen.
maSets the current cursor position as mark A. You can use any letter for the mark name.
nRepeats the last search in the same direction (forward).
NRepeats the last search in the opposite direction (backward).
oOpens a new line below the current line and enters insert mode.
oWhile in visual mode, this command moves the cursor to the opposite end of the currently selected area.
OOpens a new line above the current line and enters insert mode.
OWhile in visual block mode, this command moves the cursor to the opposite corner of the selected block.
pPastes the contents of the default register (") after the cursor.
PPastes the contents of the default register (") before the cursor.
qStops recording the current macro.
qaStarts recording a macro and saves it in register 'a'.
rReplaces the character under the cursor with the next character typed.
REnters replace mode, allowing you to replace multiple characters until the ESC key is pressed.
sDeletes the character under the cursor and enters insert mode to allow substitution of text (same as cl).
SDeletes the entire line and enters insert mode to allow substitution of text (same as cc).
txMoves the cursor to the position before the next occurrence of character 'x' on the current line.
TxMoves the cursor to the position after the previous occurrence of character 'x' on the current line.
uReverses the last editing action.
uIn visual mode, changes the selected text to lowercase.
URestores the last changed line to its state before any modifications were made.
UIn visual mode, changes the selected text to uppercase.
vStarts visual mode, allowing you to select text by moving the cursor. Once text is selected, you can perform various commands on it (like yanking/copying).
VStarts linewise visual mode, which allows you to select entire lines by moving the cursor.
wMoves the cursor forward to the beginning of the next word.
WMoves the cursor forward to the beginning of the next word, considering punctuation as part of the word.
xDeletes the character under the cursor and places it in the default register (").
xpTransposes the character under the cursor with the character to its right (effectively deleting and pasting).
yIn visual mode, copies (yanks) the selected text into the clipboard.
y`aCopies (yanks) the selected text and places it at the position marked as A.
y$ or YCopies the characters from the cursor position to the end of the line into the default register (").
yawCopies the word under the cursor and the space after or before it into the default register (").
yiwCopies the word under the cursor into the default register (").
ywCopies the characters of the word from the cursor position to the start of the next word into the default register (").
yyCopies the current line into the default register (").
zaToggles the open/closed state of the code fold located under the cursor.
zbPositions the cursor at the bottom of the screen.
zcCloses (collapses) the code fold located under the cursor.
zdDeletes the code fold located under the cursor.
zfManually defines a code fold from the current cursor position up to the specified motion.
ziToggles the folding functionality on or off.
zmIncreases the folding level by one, effectively closing folds at the current level.
zoOpens (expands) the code fold located under the cursor.
zrReduces the folding level by one, effectively opening folds at the outermost level.
ztPositions the cursor at the top of the screen.
zzCenters the cursor vertically on the screen.