piecewhat it controls%which lines — every line in the filesthe command — substituteoldthe pattern to findnewwhat replaces itghow often — every match, not just thefirst:%s/old/new/g
Read it left to right and it is a sentence: on every line, substitute this pattern with this text, every time it appears. Drop the % and it means "this line only".
Vim Substitute the whole file: :%s
advanced » Replace x with y on every line: :%s/x/y/g
goal
y
y
y
scratch.txt
1 x
2 x
3 x
-- NORMAL -- 1,1
keys
your keystrokes appear here as you press them
NORMAL ~/learn/vim-motions · 1/1 · :%s real vim keys trail · always esc in-editor

Best on a keyboard

“Substitute the whole file: :%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-file utf-8 LF