问题
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