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?
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.
g is a prefix to several commands. e.g. goto to move the cursor, but also gqip to format a paragraph.
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.
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.
In Vim 7.4+, the IndexedSearch plugin can be used.
Check henrik/vim-indexed-search on GitHub to ensure you get the latest version.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With