如何用 Vim 中的视觉选择替换? [英] How to substitue with the visual selection in Vim?

查看:28
本文介绍了如何用 Vim 中的视觉选择替换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现 vim 中的 substitue 有一个范围参数:

:[range]s/pattern/sring/[c]/[g]/[e]/[i]/[I]/[p]

但我想知道让替换只发生在视觉选择中是否会很方便.

有人知道怎么做吗?

解决方案

是的,你可以这样做.

视觉选择后,按:会给你:'<,'>'<,'>[range] 部分.

然后进行如下替换但请注意,这会影响整行:

:'<,'>s/foo/bar/g

如果您想将视觉选择区域中的 foo 更改为 bar only) 那么你必须使用 \%V原子:

:'<,'>s/\%Vfoo/bar/g

文章在视觉选择中搜索和替换 (archive) 有更多关于该主题的有用信息.>

I found substitue in vim has a range parameter:

:[range]s/pattern/sring/[c]/[g]/[e]/[i]/[I]/[p]

But I'm wondering if it would be handy to let the substitution occur only in the visual selection.

Anyone know how to do that?

解决方案

Yes, you could do that.

After visual selection, press : will give you :'<,'>, '<,'> is the [range] part.

Then do the substitute like below but note that this will affect the entire line(s):

:'<,'>s/foo/bar/g

If you would like to change foo to bar only in the visually selected area (i.e., character-wise or block-wise selection) then you'll have to use the \%V atom:

:'<,'>s/\%Vfoo/bar/g

The article Search and replace in a visual selection (archive) has much more useful info on the topic.

这篇关于如何用 Vim 中的视觉选择替换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆