Vim - How to search and reaplace based on search [duplicate]

南楼画角 提交于 2019-12-25 04:07:28

问题


What i would like to do :

Every time i find something based on s[w|l].*[0-9]\.\* replace the end of that string\search .* with %s/\.\*/\\\\\.\.\*/g

Already tried with standard search and replace, but couldn't do it.

Thanks


回答1:


Just wrap your search pattern in escaped parentheses \(\), and use a backreference \1 in the replacement string:

:%s/\(s[w|l].*[0-9]\)\.\*/\1\\\\.*/g

You can have several \(\) subexpressions in your search string, and can use them both in the search string itself and in the replacement string via \1, \2, ... . Subexpressions are simply numbered by order of occurence in the search string.



来源:https://stackoverflow.com/questions/27525223/vim-how-to-search-and-reaplace-based-on-search

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