Interactive search/replace regex in Vim?

前端 未结 7 2035
夕颜
夕颜 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条回答
  •  萌比男神i
    2020-12-12 10:21

    I usually use the find/substitute/next/repeat command :-)

    /old3snewn.n.n.n.n.n.n.
    

    That's find "old", substitute 3 characters for "new", find next, repeat substitute, and so on.

    It's a pain for massive substitutions but it lets you selectively ignore some occurrences of old (by just pressing n again to find the next one instead of . to repeat a substitution).

提交回复
热议问题