在 Vim 中有效地附加匹配:g/---/s/---/X/ [英] To append a match efficiently in Vim :g/---/s/---/X/
本文介绍了在 Vim 中有效地附加匹配:g/---/s/---/X/的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 Vim 中如何引用命令 g
中的匹配项?
How can you refer to the match in the command g
in Vim?
我想在匹配后放置 X 而不替换匹配.例如,在下面的命令中,没有写两次 create_title
.
I would like to put X after the match without replacing the match.
For instance, in the following command without writing the create_title
twice.
:g/create_title/s/create_title/X/
你应该得到
create_titleX
通过运行命令
create_tile
推荐答案
我不知道你为什么需要命令的 g
部分 - 替代品只会作用于匹配的行.这是您要查找的内容:
I'm not sure why you need the g
portion of the command - the substitute will only act on matching lines. Here's what you're looking for:
:%s/create_title/&X/
&
代表匹配的整个文本.
The &
represents the entire text which was matched.
这篇关于在 Vim 中有效地附加匹配:g/---/s/---/X/的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文