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

  1. On the current line: :s
  2. Whole file: :%s with g
  3. With confirmation: c flag
  4. Only inside a selection
  5. Across the project: grug-far

Create a free account