Training plan › Selection and objects
Search and replace
:s, :%s with g and c, visual ranges and grug-far.
:s/old/new/ replaces the first occurrence on the current line. % widens it to the whole file and the g flag to every occurrence on each line: :%s/old/new/g. The c flag asks for confirmation on each match. And if you select lines in Visual before pressing :, the substitution is limited to them.
5 steps · 5 min · 80 XP
- On the current line: :s
- Whole file: :%s with g
- With confirmation: c flag
- Only inside a selection
- Across the project: grug-far