How to count search results in Vim?

Nowadays (as of Vim 8.1.1270) you can use:

set shortmess-=S

to enable a count of [x/y] showing in the bottom right corner every time you do a / or ? search.

native search count

Relevant section from the Vim help

Note that if the search finds more than 99 results, Vim unfortunately just shows [x/>99]:

native search count over 99

For this reason, I personally use the google/vim-searchindex plugin, which works for any amount of results:

vim-search-index search count

(By default the plugin is limited to files with “only” less than one million lines; this can be adjusted with let g:searchindex_line_limit=2000000.)


You can count the number of matches using the n flag in the substitute command. Use the following to show number of times that some-word matches text in current buffer:

:%s/some-word//gn

You can read all the details on the vim tips wiki

Tags:

Vim