Replace complete words throughout the buffer
:%s/\<old\>/new/g
Example
Normal 0 / 2Command-line 1 / 2Normal 2 / 2old older old
oldCursor on line 1, column 1old older old
oldCursor on line 1, column 1new older new
newCursor on line 2, column 1Use word boundaries to avoid replacing text inside longer words.
Command entered · ready to apply
3 matches replaced · older stays
Before & after
old older old
oldCursor on line 1, column 1new older new
newCursor on line 2, column 1Start in Normal mode, at line 1, column 1 (one-based). The percent range covers all lines. Word boundaries use the active iskeyword setting; g replaces each match on a line. This example assumes gdefault and edcompatible are off. Type :%s/\<old\>/new/g and press Enter.
Details & Vim help
Example replayed in Vim
Use word boundaries to avoid replacing text inside longer words.
The percent range covers all lines. Word boundaries use the active iskeyword setting; g replaces each match on a line. This example assumes gdefault and edcompatible are off.