Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show Count of Matches in Vim

Tags:

vim

search

There is a nice feature in Google Chrome when you do a search. It tells you the number of matches there is for the keyword you are searching for. However, in Vim I don't see such a feature. Some people suggested using %s/pattern//gn or similar:

http://vim.wikia.com/wiki/Count_number_of_matches_of_a_pattern
Unable to count the number of matches in Vim

But that is quite long really!! I am looking for the count when a press the '*', '%', or do any search using '/' and '?'.

Any idea?

like image 555
Rafid Avatar asked Jan 12 '11 12:01

Rafid


People also ask

How do I count occurrences in vim?

This makes it easy to count the number of occurrences of the word under the cursor: first press * to search for the current word, then enter :%s///gn to count all occurrences of that word.

What is G in Vim?

g is a prefix to several commands. e.g. goto to move the cursor, but also gqip to format a paragraph.

How do I highlight all in Vim?

To select all in Vim, use ggVG. it allows you to select all in vim of a file's content. To go to normal mode, hit the ESC key first. Then, using the gg keys, we'll jump to the beginning of the file.


1 Answers

Modern Vim

Starting with Vim 8.1.1270, there's a new feature in core to show the current match position. NeoVim enables this functionality by default, but standard Vim does not.

To enable it in standard Vim, run:

:set shortmess-=S 

Originally mentioned below in Ben's answer, and added here for visibility.

Older Versions

In Vim 7.4+, the IndexedSearch plugin can be used.

Check henrik/vim-indexed-search on GitHub to ensure you get the latest version.

like image 70
SergioAraujo Avatar answered Sep 21 '22 09:09

SergioAraujo