Skip to content

✏️ Vim Cheat Sheet

Quick reference for Vim commands from the Vim Guide.


🔄 Modes

ModePurposeEnterExit
CommandNavigate, delete, copyEsc
InsertEdit texti, a, oEsc
Last-LineSave, quit, settings:Esc

✍️ Entering Insert Mode

KeyAction
iInsert before cursor
IInsert at beginning of line
aAppend after cursor
AAppend at end of line
oNew line below
ONew line above

💾 Save & Quit

CommandAction
:wSave
:qQuit
:q!Quit without saving
:wqSave and quit
ZZSave and quit (command mode)
:xSave (if changed) and quit

🧭 Navigation

Basic Movement

KeyAction
hLeft
jDown
kUp
lRight

Word Movement

KeyAction
wNext word
bPrevious word
eEnd of word

Line Movement

KeyAction
0Beginning of line
$End of line
^First non-blank character

File Movement

KeyAction
ggBeginning of file
GEnd of file
:100Go to line 100
Ctrl + fPage down
Ctrl + bPage up

✂️ Editing

Delete

CommandAction
xDelete character
dwDelete word
ddDelete line
5ddDelete 5 lines
d$Delete to end of line
d0Delete to beginning of line

Copy (Yank)

CommandAction
yyCopy line
5yyCopy 5 lines
ywCopy word
y$Copy to end of line

Paste

CommandAction
pPaste below/after
PPaste above/before

Change

CommandAction
rReplace character
cwChange word
ccChange entire line
c$Change to end of line

Undo/Redo

CommandAction
uUndo
Ctrl + rRedo
:e!Revert to saved

🔍 Search & Replace

CommandAction
/patternSearch forward
?patternSearch backward
nNext match
NPrevious match
*Search word under cursor

Replace

vim
:s/old/new/         " Replace first on line
:s/old/new/g        " Replace all on line
:%s/old/new/g       " Replace all in file
:%s/old/new/gc      " Replace all with confirm

👁️ Visual Mode (Selection)

CommandAction
vCharacter selection
VLine selection
Ctrl + vBlock selection

After selecting:

  • y — Copy
  • d — Cut
  • > — Indent
  • < — Unindent

📂 Multiple Files

Opening

bash
vim file1 file2      # Sequential
vim -o file1 file2   # Horizontal split
vim -O file1 file2   # Vertical split
vim -d file1 file2   # Diff mode
CommandAction
:nNext file
:NPrevious file
:lsList buffers

Splits

CommandAction
:sp fileHorizontal split
:vsp fileVertical split
Ctrl + w wSwitch window
Ctrl + w qClose window

⚙️ Settings

CommandAction
:set nuShow line numbers
:set nonuHide line numbers
:syntax onSyntax highlighting on
:syntax offSyntax highlighting off
:set pastePaste mode (no auto-indent)

🔧 Useful Commands

CommandAction
:!cmdRun shell command
.Repeat last command
>>Indent line
<<Unindent line
~Toggle case
JJoin lines

📋 Common Workflows

Delete line and start typing

cc

Delete word and replace

cw

Copy 5 lines and paste

5yy → move → p

Search and replace all

:%s/old/new/g

Save as new file

:w newfile.txt

Compare two files

bash
vimdiff file1 file2

💡 Tip: Run vimtutor for interactive practice!

Released under the MIT License.