Vim / Neovim Cheat Sheet

New

Vim modes, navigation, editing commands, search/replace, and essential configuration

Modes

Normal Mode

Default mode for navigation and commands. Press Esc to return.

Esc or Ctrl+[ → enter Normal mode : → enter Command mode

Insert Mode

Type text. Enter from Normal mode.

i → insert before cursor a → append after cursor I → insert at start of line A → append at end of line o → open new line below O → open new line above

Visual Mode

Select text for operations.

v → visual (character) V → visual line Ctrl+v → visual block

Command Mode

Execute Ex commands after pressing :

:w → save :q → quit :wq → save and quit :q! → quit without saving :e file → open file

Navigation

Basic Movement

Move cursor without arrow keys (works in all modes)

h ← j ↓ k ↑ l → 0 → start of line ^ → first non-blank character $ → end of line

Word Navigation

Jump between words efficiently

w → next word start b → previous word start e → next word end W/B/E → same but WORD (space-separated)

File Navigation

Jump to positions in the file

gg → first line G → last line 50G → line 50 Ctrl+d → half-page down Ctrl+u → half-page up Ctrl+f → full page down Ctrl+b → full page up

Character Search

Jump to a character on the current line

f{char} → forward to char (inclusive) t{char} → forward to char (exclusive) F{char} → backward to char ; → repeat last f/t/F/T , → repeat in opposite direction

Editing

Delete

Delete text (also cuts to clipboard)

dd → delete line dw → delete word d$ → delete to end of line d0 → delete to start of line D → delete to end of line

Yank (Copy) & Paste

Copy text and paste it

yy → yank (copy) line yw → yank word y$ → yank to end of line p → paste after cursor P → paste before cursor

Change

Delete and enter Insert mode

cc → change line cw → change word ci" → change inside quotes ca( → change around parens c$ → change to end of line

Undo & Redo

Undo and redo changes

u → undo Ctrl+r → redo . → repeat last change

Visual Mode

Visual Operations

Select text then apply an operation

v then w, w, w → select 3 words V then j, j → select 3 lines d → delete selection y → yank selection > → indent selection < → de-indent selection ~ → toggle case

Search & Replace

Search

Search forward and backward in file

/pattern → search forward ?pattern → search backward n → next match N → previous match * → search word under cursor

Substitute

Find and replace with :s command

: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

Multiple Files

Buffers

Open files loaded into memory

:ls → list buffers :bn → next buffer :bp → previous buffer :b name → switch to buffer by name

Windows & Tabs

Split the editor into panes or tabs

:sp file → horizontal split :vsp file → vertical split Ctrl+w h/j/k/l → navigate splits :tabnew file → open in new tab gt / gT → next/prev tab

Common Patterns

Text Objects (Motion + Object)

Vim's most powerful feature: operate on semantic units

# Pattern: [operator][inner/around][object]
# operators: d (delete), c (change), y (yank), v (visual)
# i = inner, a = around (includes delimiters)

diw    # delete inner word (not surrounding spaces)
daw    # delete a word (including trailing space)
di"    # delete inside double quotes
da"    # delete inside + the quotes themselves
ci(    # change inside parentheses
ca{    # change around curly braces (including {})
yit    # yank inside HTML/XML tag
vip    # visual select inner paragraph

Macro Recording

Record and replay a sequence of commands

# Record macro to register 'a'
qa      # start recording into register a
  ...   # perform your commands
q       # stop recording

# Replay macro
@a     # run macro a once
10@a   # run macro a 10 times
@@     # repeat last macro

# Example: add semicolon to end of 5 lines
qa A;<Esc> j q
5@a

Global Search and Replace

Powerful substitution across file with regex

# Basic substitution
:%s/foo/bar/g         # replace all 'foo' with 'bar'

# Case insensitive
:%s/foo/bar/gi        # g=all, i=case insensitive

# With confirmation
:%s/foo/bar/gc        # c=confirm each

# Regex substitution
:%s/\(\w\+\)/[\1]/g  # wrap each word in brackets

# Only in selected range (visual mode first)
:'<,'>s/foo/bar/g

Tips & Best Practices

Think in motions + text objects — daw, ci", yip are far more efficient than letter-by-letter edits

Use . (dot) to repeat the last change — it makes repetitive edits nearly instant

Start with vimtutor (run in terminal) — it takes ~30 minutes and covers the essentials interactively

Add :set number and :set relativenumber to your .vimrc for line numbers

Remap Caps Lock to Ctrl or Esc at the OS level to reduce finger travel