vim search and replace limited to the highlight in visual block mode

后端 未结 3 718
迷失自我
迷失自我 2021-02-01 16:31

I often have text in columns and need to replace some things without clobbering similar stuff on the same line... a simple example follows:

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-01 17:29

    You need to add \%V to your pattern. From :help \%V:

    Match inside the Visual area.  When Visual mode has already been
    stopped match in the area that gv would reselect.
    This is a /zero-width match.  To make sure the whole pattern is
    inside the Visual area put it at the start and end of the pattern.
    

    OP EDIT: the explicit solution is to to use : s/\%V8\%V0/81/g

提交回复
热议问题