Click any command to expand the explanation.
🚪 Getting Out (The Most Googled Question)
:q — quit exit
:q # Quit (fails if unsaved changes) :q! # Quit without saving (force) :wq # Save and quit :x # Save and quit (same as :wq) ZZ # Save and quit (no colon needed) ZQ # Quit without saving (no colon needed)If you're stuck, press
Esc first, then type :q! and hit Enter.
🎯 Modes
Normal → Insert → Visual modes
# Enter Insert mode (type text) i # Insert before cursor a # Insert after cursor I # Insert at beginning of line A # Insert at end of line o # New line below O # New line aboveBack to Normal mode
Esc # or Ctrl+[
Enter Visual mode (select text)
v # Character-wise selection V # Line-wise selection Ctrl+v # Block (column) selection
Enter Command mode
: # Type a command at the bottom
🧭 Movement
Basic movement move
h # Left j # Down k # Up l # RightBy word
w # Next word start b # Previous word start e # Next word end W/B/E # Same but WORD (whitespace-separated)
By line
0 # Beginning of line ^ # First non-blank character $ # End of line
Jumping around move
gg # Go to first line G # Go to last line 5G # Go to line 5 :42 # Go to line 42{ # Previous blank line (paragraph up) } # Next blank line (paragraph down)
Ctrl+d # Half page down Ctrl+u # Half page up Ctrl+f # Full page down Ctrl+b # Full page up
% # Jump to matching bracket ( ) [ ] { }
Search movement move
f{char} # Jump to next {char} on this line
F{char} # Jump to previous {char}
t{char} # Jump to just before next {char}
; # Repeat last f/F/t
, # Repeat last f/F/t (reverse)
-
# Search for word under cursor (forward)
# Search for word under cursor (backward)
✏️ Editing
Delete / change / yank edit
operator + motion.
# Delete x # Delete character under cursor dd # Delete entire line dw # Delete to next word d$ # Delete to end of line D # Same as d$ d3j # Delete 3 lines downChange (delete + enter insert mode)
cc # Change entire line cw # Change word c$ # Change to end of line C # Same as c$ ci” # Change inside quotes ci( # Change inside parentheses
Yank (copy)
yy # Yank entire line yw # Yank word y$ # Yank to end of line
Paste
p # Paste after cursor P # Paste before cursor
Text objects — the Vim superpower edit
i = inside, a = around (includes delimiters). Combine with d/c/y.
ci" # Change inside "quotes"
ca" # Change around "quotes" (includes the quotes)
di( # Delete inside (parentheses)
da{ # Delete around {braces}
ci[ # Change inside [brackets]
dit # Delete inside HTML tag
cit # Change inside HTML tag
ciw # Change inner word
daw # Delete a word (includes trailing space)
dip # Delete inner paragraph
yap # Yank a paragraph
This is what makes Vim fast. ci" to change the contents of a string is incredibly useful.
Undo / redo edit
u # Undo Ctrl+r # Redo . # Repeat last change (the dot command)The dot command is one of Vim's best features. Make a change, then press
. to repeat it.
Indent / format edit
>> # Indent line right << # Indent line left 3>> # Indent 3 lines = # Auto-indent (use with motion) gg=G # Auto-indent entire fileIn visual mode
# Indent selection< # Unindent selection
🔍 Search & Replace
/pattern — search search
/text # Search forward ?text # Search backward n # Next match N # Previous matchCase insensitive
/text\c
Regex
/\d+ # One or more digits /^func # Lines starting with “func”
Clear search highlighting
:noh
:%s/old/new/g — search & replace search
# Replace all in file :%s/old/new/gReplace with confirmation
:%s/old/new/gc
Replace in current line only
:s/old/new/g
Replace in lines 5-10
:5,10s/old/new/g
Replace in visual selection
(select with V, then type :)
:’<,‘>s/old/new/g
Case insensitive
:%s/old/new/gi
Use regex
:%s/\d+/NUMBER/g
📑 Windows & Tabs
Split windows windows
:split file # Horizontal split :vsplit file # Vertical split Ctrl+w s # Split current file horizontally Ctrl+w v # Split current file verticallyNavigate between splits
Ctrl+w h/j/k/l # Move to left/down/up/right split Ctrl+w w # Cycle through splits
Resize
Ctrl+w = # Equal size Ctrl+w + # Taller Ctrl+w - # Shorter
Close
Ctrl+w q # Close current split
Tabs & buffers windows
# Tabs :tabnew file # Open file in new tab gt # Next tab gT # Previous tab :tabclose # Close tabBuffers
:e file # Open file in current buffer :ls # List open buffers :bn # Next buffer :bp # Previous buffer :bd # Close buffer
⚡ Power Moves
Macros advanced
qa # Start recording into register 'a' ... # Do your edits q # Stop recording @a # Play macro 'a' @@ # Repeat last macro 10@a # Play macro 'a' 10 timesExample: Record
qa0f"ci"replacement<Esc>jq to change the first quoted string on each line, then 10@a to repeat 10 times.
Marks advanced
ma # Set mark 'a' at cursor position 'a # Jump to line of mark 'a' `a # Jump to exact position of mark 'a' :marks # List all marksLowercase marks are per-file. Uppercase marks are global (across files).
Useful commands advanced
:!command # Run shell command
:r !command # Insert command output into file
:r file # Insert file contents
:w !sudo tee % # Save file you opened without sudo
J # Join current line with next
~ # Toggle case of character
gU{motion} # Uppercase
gu{motion} # Lowercase
Ctrl+a # Increment number under cursor
Ctrl+x # Decrement number under cursor