Unable to count the number of matches in Vim

How can you count the number of matches in Vim?

For instance, for the text

<?

Upvotes: 9

Views: 1940

Answers (3)

konyak
konyak

Reputation: 11716

: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

Upvotes: 1

RedBlueThing
RedBlueThing

Reputation: 42532

Count-items describes what you are after.

:%s/<?/whatever/ng

This is the substitution command, but the n flag avoids the actual substitution.

Upvotes: 9

Brian Carper
Brian Carper

Reputation: 72946

:%s/<?//ng

See :h count-items.

Upvotes: 13

Related Questions