如何计算单词出现在文件中或某个范围内的次数 [英] How to compute the number of times word appeared in a file or in some range
本文介绍了如何计算单词出现在文件中或某个范围内的次数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有时我想查看某个函数在文件或代码块中被调用了多少次.你是怎样做的?我使用的是 Vim 7.2.
Sometimes I want to see how many times a certain function is called in a file or a code block. How do you do that? I am using Vim 7.2.
我想你必须使用 !wc
或类似的东西.
I presume you have to use !wc
or some such.
推荐答案
要计算某个模式出现的次数,请使用:
For counting the number of times some pattern occurs, use:
:%s/pattern//gn
'n' 标志计算出现的次数,而不对文档进行任何更改.
The 'n' flag count the number of occurrences without doing any change to the document.
要计算总字数,您有多种选择.
For counting the total number of words, you have several options.
如果您想作为外部命令运行:
If you want to run as an external command:
:!wc -w %
如果你想在 VIM 中运行它:
If you want to run it inside VIM:
:w !wc -w
这篇关于如何计算单词出现在文件中或某个范围内的次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文