Find and replace strings in vim on multiple lines

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

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

11条回答
  •  借酒劲吻你
    2020-12-02 03:55

    To answer this question:

    :40,50s/foo/bar/g

    replace foo with bar in these lines between the 40th line and the 50th line(inclusive), when execute this command you can currently in any line.

    :50,40s/foo/bar/g

    also works, vim will ask you for comfirm and then do the replacement for you as if you have input the first command.

    :,50s/foo/bar/g

    replace foo with bar in these lines between the line you are currently in and the 50th line(inclusive). (if you are in a line AFTER the 50th line vim will ask for confirm again)

    To clearity the difference between vim and the vrapper plugin of Eclipse:

    Note that in varpper

    :,50s/foo/bar/g command will NOT work.

    :50,40s/foo/bar/g will work without asking for comfirmation.

    (For Vrapper Version 0.74.0 or older).

提交回复
热议问题