Skip to Content
Practical Vim, 2nd Edition
book

Practical Vim, 2nd Edition

by Drew Neil
October 2015
Intermediate to advanced
356 pages
7h 54m
English
Pragmatic Bookshelf
Content preview from Practical Vim, 2nd Edition
Tip 86Count 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.

Count Matches with the ‘:substitute’ Command

We can get a ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning the vi and Vim Editors, 8th Edition

Learning the vi and Vim Editors, 8th Edition

Arnold Robbins, Elbert Hannah
Modern Vim

Modern Vim

Drew Neil
Learning the vi and Vim Editors, 7th Edition

Learning the vi and Vim Editors, 7th Edition

Arnold Robbins, Elbert Hannah, Linda Lamb

Publisher Resources

ISBN: 9781680501629Errata Page