VIM如何替换“AA"到“BB"在一个文件中 [英] VIM how to replace "AA" to "BB" in a file

查看:29
本文介绍了VIM如何替换“AA"到“BB"在一个文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要替换一个包含数千行代码的文件.

在日志中,它有一个特定的词,我想用其他词替换这个作品.

请问,如何将这个文件中的AA"全部替换为BB"?

谢谢

解决方案

您要使用

:%s/\/BB/g

% 指定您要替换所有 行.

s 告诉 vim 你想做一个替换

在第一个 / 和第二个 / 之间是您要替换的内容(即 \).>

\<\>词边界,确保 AA 匹配但 fAAAAg 不是.

在第二个/和第三个/之间是你的替代品(即BB)

最后的 g 表示你想替换一行中所有出现的地方(不仅是第一个).

I need to replace a file which has thousand of lines code.

In the log, it has a specific word which I want to replace this work with some other words.

Say, how to replace all "AA" to "BB" in this file?

thanks

解决方案

You want to use

:%s/\<AA\>/BB/g

% specifies that you want to replace on all lines.

s tells vim that you want to do a substitution

Between the first / and second / is what you want to replace (ie \<AA\>).

The \< and the \> are word boundaries, making sure that AA is matched but fAA or AAg is not.

Between the second / and third / is your replacement (ie BB)

The final g says that you want to replace all occurances on a line (not only the first).

这篇关于VIM如何替换“AA"到“BB"在一个文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆