要替换的文本

$ cat demo.txt
my name is tom.
do you name is tom?
yes my name is tom, too.

语法

:[addr]s/源字符串/目的字符串/[option]

在底行模式下进行替换

单行替换

$ vim demo.txt

# :s/源字符串/目的字符串/g
:s/tom/steve/g

cat demo.txt
my name is steve.
do you name is tom?
yes my name is tom, too.

全局替换

$ vim demo.txt

# %s/源字符串/目的字符串/g
:%s/tom/jack/g

$ cat demo.txt
my name is jack.
do you name is jack?
yes my name is jack, too.