October 2015
Intermediate to advanced
356 pages
7h 54m
English
| Tip 86 | Count the Matches for the Current Pattern |
This tip shows a couple of ways that you can count the number of matches for a pattern.
Suppose we want to find out how many times the word “buttons” appears in this excerpt:
| | var buttons = viewport.buttons; |
| | viewport.buttons.previous.show(); |
| | viewport.buttons.next.show(); |
| | viewport.buttons.index.hide(); |
We’ll start by searching for that word:
| => | /\<buttons\> |
Now we can move from one match to another by pressing the n and N keys, but Vim’s search command doesn’t give us any indication of how many matches are in the current document. We can get a match count by using either the :substitute or :vimgrep command.
We can get a ...