Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know this works:


But it seems a bit strange to use the substitution command to count, rather than global..

share|improve this question
up vote 8 down vote accepted

I've previously used a plugin for this. vim-indexed-search gives you a message in the command line such as:

2 of 32 matches

For searches using /

share|improve this answer

It seems there's no other way. Indeed, this is the official way described in the Vim documentation.

See this SO question titled: Counting occurrences in Vim without marking the buffer changed and by extension this paragraph from the Vim documentation.

Alternatively there's this SO question too, titled: Search for string and get count in vi editor, but note that this method will only count lines not actual matches, so if you have multiple matches per line, you'll not get a correct count.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.