tags:

views:

334

answers:

2

How can you count the number of matches in Vim?

For instance, for the text

<?
+5  A: 
:%s/<?//ng

See :h count-items.

Brian Carper
I get the error message "Trailing characters". I tried the code with ":set report=0" too.
Masi
I would try it again, the help for Trailing Characters describes "An argument has been added to an Ex command that does not permit one."
Cannonade
@Cannonade: The same error again with the code E488.
Masi
Hrmm .. Sorry Masi, don't know what is going on for you. I just double check this in a vim buffer on my machine, and it worked ok.
Cannonade
If you copy/paste the code from a web browser you may pick up a trailing newline (^M). Try typing it in manually.
Brian Carper
@Brian: I found the source of the problem. The Vim at my server is version 6.3. The code works great when I run it on Vim 7.2. Thank you for your help!
Masi
+7  A: 

Count-items describes what you are after.

:%s/<?/whatever/ng

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

Cannonade