Nav

Vim Reference

Edit me

For another Vim quick reference sheet, take a look at this:

Vim Cheat Sheet

Vim Commands

Command Description
:q Quit – fails when there are unsaved changes
:q! Forcibly quits without writing changes.
:x Exit – quits and saves changes
:w Write changes to disk
:w <file> Write the current buffer to <file>
:e Edit – useful for reloading the file, when it has been changed outside of Vim
:e <file> Load and edit <file> in a new buffer
i Enter insert mode
[esc] Leave the current mode
dd Delete lines
u Undo changes
gJ join current and next line (SO Q&A #1912905)
/pattern search for the given RegEx search pattern
?pattern search backwards for the given search pattern
n jump to the next match
N jump to the previous match
:noh clears highlighting from the last search (SO Q&A #657447)
CTRL + g display line & column of cursor on status line (SO Q&A #14993012)
1 CTRL+G display full path of the current file on the status line
v Visual – select text
d Cut selection in visual mode
y Yank – Copy selection in visual mode
P Paste before cursor
p Paste after cursor
> Indent – shift selection reight in visual mode
< Unindent – shift selection left in visual mode
. (Dot) Repeat last command
:syntax off Disable syntax highlighting
set tabstop=4 softtabstop=0
noexpandtab shiftwidth=4
SO Q&A #1878974
:set nu[mber] show line numbers
:set nonu[mber] hide line numbers
:set number! or :set nu! toggle the display of line numbers
:set nowrap disables line wrapping
:set paste
:set nopaste
toggles auto indentation; used to temporarily disable auto indent to paste
:reg[isters] or :di[splay] displays the contents of all numbered and named registers
:!somecommand run an external command
:!echo % view the path opened with vim
:w !diff % - before saving, see the changes in the buffer from the current file on disk
:prev
:next
<p>switch between files when multiple files have been opened in vim:</p><p>vim file1.txt file2.txt file3.txt</p>
:%s/foo/bar/g globally replace all occurrences of foo with bar
:6,10s/foo/bar/g replace all occurrences of foo with bar on lines 6 - 10
:6,10s/foo/bar/g | 14,18&& replace all occurrences of foo with bar on lines 6 - 10 and 14 - 18

Resources