Sunday 15 February 2015

How to share searchText between vim search and vim substitute? -


When I need to convert a string with a new string in vim.

I'll first use the search to check that the search pattern is correct

  / search pattern   

then to replace Use 's' command for.

 :% s / search pattern / new string /   

The search pattern must be typed twice if it is too complex, it will be boring.

Is there any way to avoid this?

apart from (in addition to the correct answer to Marco Baldelli), the last search pattern Special register is stored in / . You can insert it in the command line through Ctrl + R , then / . (It also works in insert mode, and also with other registers.) It is useful when you want to change your search patterns before replacing.

No comments:

Post a Comment