计算 Vim 中的出现次数而不标记缓冲区已更改 [英] Counting occurrences in Vim without marking the buffer changed

查看:15
本文介绍了计算 Vim 中的出现次数而不标记缓冲区已更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了知道模式在当前缓冲区中存在多少次,我这样做:

In order to know how many times a pattern exists in current buffer, I do:

:%s/pattern-here/pattern-here/g

它给出了模式出现的次数,但显然很麻烦,而且还有设置已更改"状态的副作用.

It gives the number of occurrences of the pattern, but is obviously cumbersome and also has the side-effect of setting the 'changed' status.

有没有更优雅的计数方式?

Is there a more elegant way to count?

推荐答案

为避免替换,将第二个模式留空,并添加n"标志:

To avoid the substitution, leave the second pattern empty, and add the "n" flag:

:%s/pattern-here//gn

这被描述为官方提示.

这篇关于计算 Vim 中的出现次数而不标记缓冲区已更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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