Vim / Neovim Search, Substitute, and Macros

Search efficiently, run substitutions, and automate repetitive edits with macros.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

Search navigation

Search forward and backward and reuse patterns efficiently.

Search forward

Find the next match after the cursor.

vimANYvimsearchpattern
vim
/pattern
Notes

Type Enter to execute the search.

Search backward

Search upward through the file.

vimANYvimsearchpattern
vim
?pattern
Notes

Useful when you overshoot or are tracing a prior reference.

Jump among matches

Repeat the last search in either direction.

vimANYvimsearchnavigation
vim
n  N
Notes

`n` follows the search direction and `N` reverses it.

Search for word under cursor

Search the symbol at the cursor instantly.

vimANYvimsearchsymbol
vim
*  #
Notes

Great for moving through repeated identifiers in code.

Substitution patterns

Use Ex substitution commands for local and global refactors.

Substitute on current line

Replace matches only on the current line.

vimANYvimsubstitutereplace
vim
:s/old/new/g
Notes

The `g` flag replaces all matches on the current line.

Substitute in entire file

Perform a global replacement across the buffer.

vimANYvimsubstitutereplace
vim
:%s/old/new/gc
Notes

Add `c` to confirm each replacement interactively.

Substitute inside visual selection

Restrict replacement to a selected range.

vimANYvimsubstitutevisual
vim
:'<,'>s/old/new/g
Notes

Visual ranges are useful for safer targeted edits.

Clear search highlight

Remove visual search highlighting.

vimANYvimsearchhighlight
vim
:nohlsearch
Notes

Keeps the screen clean after repeated searching.

Macros

Record and replay repeatable editing sequences.

Record a macro

Start recording keystrokes into a register.

vimANYvimmacrosregisters
vim
qq
Notes

Start with `q{register}` and press `q` again to stop.

Play a macro

Execute a recorded macro once or many times.

vimANYvimmacrosautomation
vim
@q  10@q
Notes

Counts let you replay the macro over many lines.

Repeat last macro

Run the last-executed macro again.

vimANYvimmacrosautomation
vim
@@
Notes

Useful when stepping through repetitive records line by line.

Run a macro over a range

Apply a macro to every line in a selected range.

vimANYvimmacrosvisual
vim
:'<,'>normal @q
Notes

A very efficient way to transform multiple lines using one recording.

Recommended next

No recommendations yet.