Vim - 搜索并替换结果 [英] Vim - Search and replace the results
问题描述
但是,只有一个简单的功能,我无法从网上得到任何答案。那就是搜索并替换结果。问题是,我知道:
:要搜索的关键字,而敲入输入关键字会突出显示(当然还有设置hlsearch)
n,或者N导航
:%s / keyword / new_keyword / g用new_keyword替换关键字的所有出现。
但是,我认为必须有一种方法来搜索,并用任何new_keyword代替匹配的关键字(突出显示),而不用做:%s / keyword / new_keyword / g,这是很多打字考虑搜索&替换是这样一个日常的功能。
任何答案/评论将不胜感激!
如果您已经完成了搜索,只需在替换命令中省略模式即可替换相同的模式。例如:
/关键字
搜索keyword,然后:
:%s // new_keyword / g
会将所有出现的keyword替换为new_keyword。
I'm getting more and more comfortable with Vim after a few months. BUT, there is only one simple feature I can't get any answer from the web. That is "Search and replace the results". The problem is that I know:
:/keyword to search, and hit enter "keyword" will be highlighted (of course with set hlsearch) n, or N to navigate
:% s/keyword/new_keyword/g to replace all occurences of keyword with new_keyword.
BUT, I would think that there must be a way to search, and replace the matched keyword (highlighted) with any new_keyword WITHOUT doing ":% s/keyword/new_keyword/g", which is a lot of typing considering search & replace is such a day-to-day feature.
Any answers/comments will be greatly appreciated!
If you've already done a search you can do a substitution for the same pattern by simply leaving out the pattern in the substitute command. eg:
/keyword
searchs for "keyword", and then:
:%s//new_keyword/g
will replace all occurrences of "keyword" with "new_keyword".
这篇关于Vim - 搜索并替换结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!