问题
How can you count the number of matches in Vim?
For instance, for the text
<?
回答1:
:%s/<?//ng
See :h count-items
.
回答2:
Count-items describes what you are after.
:%s/<?/whatever/ng
This is the substitution command, but the n flag avoids the actual substitution.
回答3:
:help count-items
In VIM 6.3, here's how you'd do it:
:set report=0
:%s/<?/&/g # returns the count without substitution
In VIM 7.2, here's how you'd do it:
:%s/<?/&/gn # returns the count without substitution
来源:https://stackoverflow.com/questions/647049/unable-to-count-the-number-of-matches-in-vim