在 vi 中一次性显示出所有搜索的匹配
在 vi 中,普通的搜索按/
,然后输入匹配条件,每次只能匹配到一个,如果有很多个,就费时费力,如果一次性显示出所有搜索的匹配呢?
完整形式
:global/regular-expression/print
简写形式
:g/regex/p
再简:
:g//
更简:
:g/
筛选出结果的同时显示行号
:g/regex/#
例子文件
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 协议》,转载必须注明作者和本文链接