开发者

VIM: use incremental search for file replace

开发者 https://www.devze.com 2023-04-12 23:09 出处:网络
I know that t开发者_StackOverflow中文版he incsearch setting controls how search in vim highlights as you type. I would like to have the same incremental search and highlight when using the replace com

I know that t开发者_StackOverflow中文版he incsearch setting controls how search in vim highlights as you type. I would like to have the same incremental search and highlight when using the replace command (:%s/foo/bar/ )


The easiest way to do that is to do a search like normal, using 'incsearch' to help ensure the pattern is matching what you want. Once you've got that nailed down, you can either

  • Leave out the search pattern in :%s//bar/. When there's no specified search pattern, the current value of the / register is used, which will be the search you just did.
  • Insert the search pattern into the :s command using Ctrl+r/ (see :help c_ctrl-r) or Ctrl+rCtrl+o/ (if the search contains control characters, like ^H). This is useful if you want to make some final tweaks to the pattern or if you want to have it in your command history so you can reuse it even after performing another search.


You could add c at the end of your command like that:

:%s/foo/bar/c

It will walk through all the instances of foo and ask for your confirmation (that's what the c stands for) before changing it to bar.

It's not exactly what you are after though.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号