Replace all matches in a file
:%s/old/new/g
Example
Normal 0 / 2Command-line 1 / 2Normal 2 / 2old old
oldCursor on line 1, column 1old old
oldCursor on line 1, column 1new new
newCursor on line 2, column 1Replace old throughout the buffer.
Command entered · ready to apply
Replace old throughout the buffer
Before & after
old old
oldCursor on line 1, column 1new new
newCursor on line 2, column 1Start in Normal mode. Cursor starts anywhere. Execute :%s/old/new/g and press Enter.
Details & Vim help
Example replayed in Vim
Replace old throughout the buffer.
% addresses every line. With gdefault and edcompatible off, g replaces every match in each line. Patterns and replacement strings have Vim-specific escaping rules.