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
/pattern

# Find the next match after the cursor.

Search backward
?pattern

# Search upward through the file.

Jump among matches
n  N

# Repeat the last search in either direction.

Search for word under cursor
*  #

# Search the symbol at the cursor instantly.

## Substitution patterns
Substitute on current line
:s/old/new/g

# Replace matches only on the current line.

Substitute in entire file
:%s/old/new/gc

# Perform a global replacement across the buffer.

Substitute inside visual selection
:'<,'>s/old/new/g

# Restrict replacement to a selected range.

Clear search highlight
:nohlsearch

# Remove visual search highlighting.

## Macros
Record a macro
qq

# Start recording keystrokes into a register.

Play a macro
@q  10@q

# Execute a recorded macro once or many times.

Repeat last macro
@@

# Run the last-executed macro again.

Run a macro over a range
:'<,'>normal @q

# Apply a macro to every line in a selected range.

Recommended next

No recommendations yet.