Interactive search/replace regex in Vim?

前端 未结 7 2028
夕颜
夕颜 2020-12-12 10:05

I know the regex for doing a global replace,

     %s/old/new/g

How do you go about doing an interactive search-replace in Vim?

相关标签:
7条回答
  • 2020-12-12 10:27

    Mark Biek pointed out using:

    %s/old/new/gc
    

    for a global search replace with confirmation for each substitution. But, I also enjoy interactively verifying that the old text will match correctly. I first do a search with a regex, then I reuse that pattern:

    /old.pattern.to.match
    %s//replacement/gc
    

    The s// will use the last search pattern.

    0 讨论(0)
提交回复
热议问题