Find and replace strings in vim on multiple lines

前端 未结 11 1819
耶瑟儿~
耶瑟儿~ 2020-12-02 03:29

I can do :%s///g for replacing a string across a file, or :s///

11条回答
  •  长情又很酷
    2020-12-02 03:49

    We don't need to bother entering the current line number.

    If you would like to change each foo to bar for current line (.) and the two next lines (+2), simply do:

    :.,+2s/foo/bar/g
    

    If you want to confirm before changes are made, replace g with gc:

    :.,+2s/foo/bar/gc
    

提交回复
热议问题