How to search and replace globally, starting from the cursor position and wrapping around the end of file, in a single command invocation in Vim?

前端 未结 6 1324
攒了一身酷
攒了一身酷 2020-12-22 18:42

When I search with the / Normal-mode command:

/\\vSEARCHTERM

Vim starts the search from the cursor position and continues downwa

6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-22 19:07

    You are already using a range, %, which is short hand for 1,$ meaning the entire file. To go from the current line to the end you use .,$. The period means current line and $ means the last line. So the command would be:

    :.,$s/\vBEFORE/AFTER/gc
    

    But the . or current line can be assumed therefore can be removed:

    :,$s/\vBEFORE/AFTER/gc
    

    For more help see

    :h range
    

提交回复
热议问题