vim search and replace using current line as reference point

后端 未结 2 1281
南旧
南旧 2021-01-30 10:50

Is there a way to specify search and replace range using the current line as a reference? I can specify range using explicit line numbers like

:5,15s/foo/bar/g
<         


        
2条回答
  •  时光说笑
    2021-01-30 11:14

    You can use . for the current position, and .+10 for 10 lines down:

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

    Some other useful ranges:

    • % for the whole file.
    • '<,'> for the lines of visually selected block. This might get you more than you want of the visual selection starts or ends in the middle of a line. The whole line is included.
    • 'a,'b from mark a to mark b.
    • .,$ from the current line to the end of the file.

提交回复
热议问题