我想在vim中替换搜索到的表达式.
例如:
我用的表达式搜索:/0x....
- >它将搜索格式的所有字符串
0x0001
,0x0002
,0x1234
,等.
现在,我想的东西,如更换上面的搜索项目0x0001_mystring
,0x0002_mystring
,0x1234_mystring
等等.
使用以下ex命令:
:%s/0x\x*/&_mystring/g
Run Code Online (Sandbox Code Playgroud)
\x
匹配hexdigit字符.相当于[0-9A-Fa-f]
.&
用整个匹配的模式替换.参考:http://vimdoc.sourceforge.net/htmldoc/pattern.html#/\x(对不起,SO \
在URL 中不喜欢)