To append a match efficiently in Vim :g/---/s/---/X/

℡╲_俬逩灬. 提交于 2019-12-20 12:31:47

问题


How can you refer to the match in the command g in Vim?

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/

You should get

create_titleX

by running the command to

create_tile

回答1:


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.




回答2:


:%s/\(create_title\)/\1X/g

works for me. (if I understand your question correctly).



来源:https://stackoverflow.com/questions/1343979/to-append-a-match-efficiently-in-vim-g-s-x

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!