beforeaaaaaa:s/aa/bb/bbaaaa:s/aa/bb/gbbbbbbWithout g, only the first match on the linechanges.
The g flag is the difference between "the first one on this line" and "all of them on this line". Leave it off by accident and the other two matches quietly survive.
Vim Find & replace: :s
intermediate » Replace cat with dog using :s/cat/dog/
goal
the dog sat
scratch.txt
1 the cat sat
-- NORMAL -- 1,1
keys
your keystrokes appear here as you press them
NORMAL ~/learn/vim-motions · 1/2 · :s real vim keys trail · always esc in-editor

Best on a keyboard

“Find & replace: :s” is a hands-on typing drill — it needs a physical keyboard. Open it on a laptop or desktop to play. You can still browse and read everything here on your phone.

Back to course →
NORMAL ~/memra/learn/vim-motions/substitute-line utf-8 LF