免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 7714 | 回复: 5
打印 上一主题 下一主题

vim如何查找同时存在某两个单词的行 [复制链接]

论坛徽章:
1
双子座
日期:2015-01-04 14:25:06
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-05-24 11:39 |只看该作者 |倒序浏览
单词出现没有先后顺序

论坛徽章:
1
双子座
日期:2015-01-04 14:25:06
2 [报告]
发表于 2011-05-24 12:40 |只看该作者
http://vim.wikia.com/wiki/Vim_Tips_Wiki:Imported_tips
Find two words in either order.
这里面有
可惜公司打不开

论坛徽章:
2
CU十二周年纪念徽章
日期:2013-10-24 15:41:34处女座
日期:2013-12-27 22:22:41
3 [报告]
发表于 2011-05-24 13:19 |只看该作者
Finding two words in either orderEdit Finding two words in either order sectionEdit

You can search for a line that contains two words, in any order. For example, the following pattern finds all lines that contain both "red" and "blue", in any order:

.*red\&.*blue

In a pattern, \& separates alternates, each of which has to match at the same position. The two alternates in this example are:

    .*red (will match all characters from the beginning of a line to the end of the last "red"); and
    .*blue (will match all characters from the beginning of a line to the end of the last "blue").

A line which contains both "red" and "blue" will match both alternates, starting at the beginning of the line. The pattern .*red\&.*blue finds the last alternate (but only if all alternates match at the same position), so if you are highlighting matches, you will see text matched by .*blue highlighted.

An alternative procedure is to use a pattern that explicitly finds "red" followed by "blue", or "blue" followed by "red":

\(red.*blue\)\|\(blue.*red\)

To search for lines that contain only the whole words "red" and "blue", in either order, use one of the following patterns:

.*\<red\>\&.*\<blue\>
\(\<red\>.*\<blue\>\)\|\(\<blue\>.*\<red\>\)

论坛徽章:
1
双子座
日期:2015-01-04 14:25:06
4 [报告]
发表于 2011-05-24 13:40 |只看该作者
回复 3# tempname2


    谢谢

论坛徽章:
0
5 [报告]
发表于 2011-05-24 14:01 |只看该作者
回复 3# tempname2


    red.*blue\|blue.*red

论坛徽章:
2
天蝎座
日期:2014-03-28 10:18:052015年亚洲杯之乌兹别克斯坦
日期:2015-02-10 11:32:25
6 [报告]
发表于 2011-05-25 09:31 |只看该作者
正则表达式啊,lz
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP