参考:https://unix.stackexchange.com/questions/35206/replace-using-vim-reuse-part-of-the-search-pattern
\0
is the whole match. To use only part of it you need to set it like this and use \1
.s/(\([0-9]*\))/{\1}/
比如想把 文件里 test_12 test_2323
等test_后面带数字的字符串,后面加一个x
变成test_12x test_2323x
%s/\(test_\d\+\)/\0x/g
注意这里括号和+号都要加转义