Mik*_*ton 25 vim search replace
我经常在列中添加文本,需要更换一些东西,而不需要在同一行上删除类似的东西...一个简单的例子如下:

假设我用vim视觉块模式突出显示灰色文本,并想要替换80为81; 但是,我只想在突出显示的视觉块中进行替换.
我已经尝试过Cntlv : s/80/81/g; 但是,它取代了可视块内外的文本.(根据兰迪的反馈,这是因为: s是一个直线命令).
我知道我可以在这个特定的实例中使用直线视觉块替换(Shiftv : s/80\.1/81.1/g); 但是,我试图找到一个通用的解决方案,在非线性视觉块中没有简单的替换方法(这不是视觉块模式应该帮助解决的那种问题吗?).需要确认的答案: s/80/81/gc,不是我要找的.
我将重申对清晰度的问题是:我怎么能代替80与81使用vim的视觉块模式的亮点?
Ran*_*ris 26
您需要添加\%V到您的模式.来自: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.
Run Code Online (Sandbox Code Playgroud)
OP EDIT:显式解决方案是使用: s/\%V8\%V0/81/g