Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to count the number of matches in Vim

Tags:

vim

count

match

How can you count the number of matches in Vim?

For instance, for the text

<?
like image 716
Léo Léopold Hertz 준영 Avatar asked Mar 15 '09 01:03

Léo Léopold Hertz 준영


3 Answers

:%s/<?//ng

See :h count-items.

like image 141
Brian Carper Avatar answered Oct 28 '22 02:10

Brian Carper


Count-items describes what you are after.

:%s/<?/whatever/ng

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

like image 44
RedBlueThing Avatar answered Oct 28 '22 02:10

RedBlueThing


: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
like image 26
konyak Avatar answered Oct 28 '22 00:10

konyak