In vim, how do I copy a regex pattern?

Sometimes I do a regular expression search with / . But then I want to use the same pattern to replace using %s . How to copy or otherwise reuse a template?

+4
source share
1 answer

for example you did

 /foo 

then you could:

 %s//bar/g 

vim will replace all foo (your last search) with bar

Your last search pattern was saved in the / register, you can get it by reading the register value. eg.

 "/p (in normal mode) 

or

 <cr>/ (in insert/command mode) 
+11
source

Source: https://habr.com/ru/post/1489543/


All Articles