vi 全文替换

发表于:2007-07-04来源:作者:点击数: 标签:
看shell by example 随便写两个例子 比如我写了如下的一个信件 % vi letter ------------------------------------------------------------------ Hi tom, I think I failed my anatomy test yesterday. I had a terrible stomach ache. I ate too many frie
看shell by example 随便写两个例子

比如我写了如下的一个信件

% vi letter
------------------------------------------------------------------
Hi tom,
I think I failed my anatomy test yesterday. I had a terrible
stomach ache. I ate too many fried green tomatoes.
Anyway, Tom, I need your help. I'd like to make the test up
tomorrow, but don't know where to begin studying. Do you
think you could help me? After work, about 7 PM, come to
my place and I'll treat you to pizza in return for your help. Thanks.
                                      Your pal,
                                      guy@phantom
我觉得tom可能出去旅游了不会收到这个邮件,我还是寄给别人那么我可以这么做

% vi letter
------------------------------------------------------------------
Hi David,
I think I failed my anaDavidy test yeserday. I had a terrible
sDavidachache. I think I ate too many fried green Davidatoes.
Anyway, Tom, I need your help. I'd like to make the test up
Davidorrow, but don't know where to begin studying. Do you
think you could help me? After work, about 7 PM, come to
my place and I'll treat you to pizza in return for your help. Thanks.
                                      Your pal,
                                      guy@phanDavid

~
~
~


 :1,$s/tom/David/g

其中 1,$表示从第一行到文本结束,/tom/David/g是正规表达式,表示将tom替换为David 那么这个命令就是全文搜索tom并将其修改为David

原文转自:http://www.ltesting.net