VIM如何替换“AA"到“BB"在一个文件中 [英] VIM how to replace "AA" to "BB" in a file
问题描述
我需要替换一个包含数千行代码的文件.
在日志中,它有一个特定的词,我想用其他词替换这个作品.
请问,如何将这个文件中的AA"全部替换为BB"?
谢谢
您要使用
:%s/\/BB/g
%
指定您要替换所有 行.
s
告诉 vim 你想做一个替换
在第一个 /
和第二个 /
之间是您要替换的内容(即 \
).>
\<
和 \>
是词边界,确保 AA
匹配但 fAA
或 AAg
不是.
在第二个/
和第三个/
之间是你的替代品(即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屋!