如何在vim中全部替换

Search and replace in the whole text in Vim can be done by :%s/from/to/gc. But how to search and replace in visual selection only?

在Vim中搜索和替换全文可以通过:%s/from/to/gc 。 但是,如何仅在视觉选择中进行搜索和替换?

The %V atom in Vim restricts a pattern so that it matches only inside the visual selection.

Vim中的%V原子限制了模式,因此它仅在视觉选择内匹配。

So, your command for searching and replacing only in the visual selection can be

因此,仅在视觉选择中用于搜索和替换的命令可以是

:%s/%Vfrom/to/gc

In addition, you can use marks for the beginning and end of the visual selection as the start,end range for the :s command:

另外,可以将标记用于视觉选择的开始和结束,作为:s命令的start ,end范围:

'<  start line
`<  start character
'>  end line
`>  end character
Answered by Eric Z Ma.
埃里克·马(Eric Z Ma)回答。

翻译自: https://www.systutorials.com/in-vim-how-to-search-and-replace-in-visual-selection/

如何在vim中全部替换

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐