在 vi 中一次性显示出所有搜索的匹配

在 vi 中,普通的搜索按/,然后输入匹配条件,每次只能匹配到一个,如果有很多个,就费时费力,如果一次性显示出所有搜索的匹配呢?

完整形式

:global/regular-expression/print

简写形式

:g/regex/p

再简:

:g//

更简:

:g/

image-20221029213503202

筛选出结果的同时显示行号

:g/regex/#

image-20221029213728337

例子文件

This file tests for book in various places, such as
book at the beginning of a line or
at the end of a line book
as well as the plural books and
handbooks.  Here are some
phrases that use the word in different ways:
"book of the year award"
to look for a line with the word "book"
A GREAT book!
A great book? No.
told them about (the books) until it
Here are the books that you requested
Yes, it is a good book for children
amazing that it was called a "harmful book" when
once you get to the end of the book, you can't believe
A well-written regular expression should
avoid matching unrelated words,
such as booky (is that a word?)
and bookish and
bookworm and so on.
本作品采用《CC 协议》,转载必须注明作者和本文链接
日拱一卒
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!
未填写
文章
93
粉丝
83
喜欢
150
收藏
121
排名:67
访问:11.4 万
私信
所有博文
社区赞助商