Vim 搜索并替换选定的文本 [英] Vim search and replace selected text
问题描述
假设我们有一个文本,我进入视觉模式并选择一些文本.如何快速搜索突出显示的文本并将其替换为其他内容?
Let's say we have a text, and I enter visual mode and select some text. How do I quickly do a search for the highlighted text and replace it with something else?
推荐答案
尝试执行以下或放入你的 .vimrc
Try execute the following or put in into your .vimrc
vnoremap <C-r> "hy:%s/<C-r>h//gc<left><left><left>
在可视模式下按 ctrl+r,系统会提示您输入要替换的文本.按 enter,然后确认您同意 y 的每项更改或使用 n 拒绝.
By pressing ctrl+r in visual mode, you will be prompted to enter text to replace with. Press enter and then confirm each change you agree with y or decline with n.
此命令将覆盖您的寄存器 h
,因此您可以选择其他不使用的寄存器(通过将上述命令中的 h
更改为另一个小写字母).
This command will override your register h
so you can choose other one (by changing h
in the command above to another lower case letter) that you don't use.
这篇关于Vim 搜索并替换选定的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!