查找并替换vim中的整个单词 [英] Find and replace whole words in vim

查看:775
本文介绍了查找并替换vim中的整个单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要查找和替换vim中某个单词的所有实例,我使用

To find and replace all instances of a word in vim, I use

%s/word/newword/g

如何更改此设置,使其仅查找完整单词的单词实例? p>

How do I change this so that it only finds instances of "word" that are whole words?

推荐答案

您可以使用 \< 来匹配单词的开头和 \> 以匹配结尾:

You can use \< to match the beginning of a word and \> to match the end:

%s/\<word\>/newword/g

这篇关于查找并替换vim中的整个单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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