Vim - 搜索和替换结果 [英] Vim - Search and replace the results

查看:27
本文介绍了Vim - 搜索和替换结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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屋!

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