Vim Recall繁體中文

Replace the first match on a line

:s/old/new/

Example

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

Replace the first old match on the current line.

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

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

Details & Vim help

Example replayed in Vim

Replace the first old match on the current line.

Enter this Ex command from Normal mode and press Enter. The pattern is a regular expression. This example assumes gdefault and edcompatible are off; gdefault reverses the meaning of g, while edcompatible can retain the prior g/c settings.