Vim Recall繁體中文

Replace all matches on a line

:s/old/new/g

Example

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

Replace every old match on the current line.

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

Start in Normal mode. Cursor starts anywhere on the only line. Execute :s/old/new/g and press Enter.

Details & Vim help

Example replayed in Vim

Replace every old match on the current line.

The g flag normally replaces all matches in each addressed line. This example assumes gdefault and edcompatible are off. It changes only the current line because no range is given.