为了知道一个模式在当前缓冲区中存在多少次,我这样做:
:%s/pattern-here/pattern-here/g它给出了模式的出现次数,但显然很麻烦,而且还具有设置“已更改”状态的副作用。
有没有更优雅的数数方法?
发布于 2008-09-16 09:18:02
为了避免替换,将第二个模式保留为空,并添加“n”标志:
:%s/pattern-here//gn这被描述为an official tip。
发布于 2013-02-01 05:49:40
:help count-items在VIM 6.3中,你可以这样做。
:set report=0
:%s/your_word/&/g # returns the count without substitution在VIM 7.2中,你可以这样做:
:%s/your_word/&/gn # returns the count, n flag avoids substitution发布于 2008-09-16 09:24:29
:!cat %| grep -c "pattern"这并不完全是vim命令,但它将为您提供vim所需的内容。
如果需要频繁使用,可以将其映射到命令。
https://stackoverflow.com/questions/70529
复制相似问题