开发者

Using vi how to obtain a number of time a word or pattern occur in the file

开发者 https://www.devze.com 2022-12-09 20:01 出处:网络
How do calculate the number from inside开发者_运维技巧 the vim?For counting the number of times some pattern occurs, use:

How do calculate the number from inside开发者_运维技巧 the vim?


For counting the number of times some pattern occurs, use:

:%s/pattern//gn


The following will work with unmodifiable files, and the result can be kept and used elsewhere in our scripts.

:let g:n = 0
:g/pattern/let g:n += 1
:echo g:n
0

精彩评论

暂无评论...
验证码 换一张
取 消