Vim Recall繁體中文

Replace all matches in a file

:%s/old/new/g

Example

Normal 0 / 2
old old
old
Cursor on line 1, column 1

Replace old throughout the buffer.

Before & after
Before
old old
old
Cursor on line 1, column 1
After
new new
new
Cursor on line 2, column 1

Start 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.