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

后端 未结 3 675
迷失自我
迷失自我 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:12

    The solution is obviously the \%V regex atom, but note, that this it still a little bit buggy.

    Update: It's no bug. This thread explains the behaviour.

    0 讨论(0)
  • 2021-02-01 17:21

    The visual selection block should be identifiable with %V

    :'<,'>s/\%V80/81/g
    
    0 讨论(0)
  • 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

    0 讨论(0)
提交回复
热议问题