~/ learn/ comp-325/ cards/ Two editors, one buffer
1 of 10

The substitute command, one range at a time

The substitute command, one range at a time

Answer

:s/old/new/ :s/old/new/g :1,$s/old/new/g :%s/\<log\>/trace/gc

Escalate the range, not the strings. Line 1 changes the first match on the current line only; line 2 changes every match on that line; line 3 covers line 1 through the last line (`$`); line 4 is the vim shorthand `%` for the whole file, matching `log` only as a whole word (`\<` and `\>`) and asking for confirmation at each match (`c`).

Sarwar & Koretsky 3e ch3 §3.1–3.4

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/94253408-baa7-4682-b52d-0d140d2449d2/flashcard utf-8 LF