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 1306
攒了一身酷
攒了一身酷 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:25

    % is a shortcut for 1,$
    ( Vim help => :help :% equal to 1,$ (the entire file).)

    . is the cursor postion so you can do

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

    To replace from the beginning of the document till the cursor

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

    etc

    I strongly suggest you read the manual about range :help range as pretty much all commands work with a range.

提交回复
热议问题