1. 程式人生 > >Replace using VIM, reuse part of the search pattern

Replace using VIM, reuse part of the search pattern

hole ng- gpo sin ear ack att ace test

參考: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

註意這裏括號和+號都要加轉義

Replace using VIM, reuse part of the search pattern