Vim Recall繁體中文

Replace complete words throughout the buffer

:%s/\<old\>/new/g

Example

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

Use word boundaries to avoid replacing text inside longer words.

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

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