Vim / Neovim Search, Substitute, and Macros/Substitute inside visual selection

Restrict replacement to a selected range.

Section: Substitution patterns

Substitute inside visual selection

vim
vim
:'<,'>s/old/new/g
Explanation

Visual ranges are useful for safer targeted edits.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Substitution patterns
Substitute on current line
Replace matches only on the current line.
OpenIn sheetvimsame section
Substitute in entire file
Perform a global replacement across the buffer.
OpenIn sheetvimsame section
Clear search highlight
Remove visual search highlighting.
OpenIn sheetvimsame section
Run a macro over a range
Apply a macro to every line in a selected range.
OpenIn sheetvim2 tag match
Search forward
Find the next match after the cursor.
OpenIn sheetvim1 tag match
Record a macro
Start recording keystrokes into a register.
OpenIn sheetvim1 tag match