Inspired by modern browsers, I'd love to be able to see how many occurrences there are of some string, when I search for it – like the "10 of 37" at the top-right corner of the screenshot below.

Chrome 10 of 37

Is there a way of getting this in Emacs? Presumably, so as to not be slow, it should run only after some idle time.

  • This is a duplicate of these [emacs]-tagged questions on StackOverflow: stackoverflow.com/q/14764130/729907, stackoverflow.com/q/22479140/729907. Apparently it cannot be closed as a duplicate, so I guess that means that folks can copy the zillions of other SO [emacs]-tagged questions... Bonjour les degats. – Drew Oct 10 '14 at 4:00
  • @Drew: Thanks for those pointers. Obviously it's not reasonable to consider questions as duplicates across different websites, any more than you'd consider a question here a "duplicate" of something asked somewhere else (e.g. on gnu.emacs.help). Yes the hope for this site is that if good questions from SO are reproduced here, it should improve the quality of this site. I didn't know the question had been asked on SO, but it's definitely a good idea for someone with the time to start asking (and answering) the best questions here. Maybe there should be a way to migrate questions automatically. – ShreevatsaR Oct 10 '14 at 5:26
  • Why? Why is it a good thing to reproduce the "good questions from SO" here? What is the aim? This Beta tests whether it makes sense to have a separate Emacs site, as opposed to using tag [emacs] on SO etc. If we "prove" that this site is meaningful by just copying questions from elsewhere, then what have we shown? This makes no sense to me. And why would we want to encourage such behavior? Who does it help (besides the copier)? If we wanted to migrate stuff (which we do not, during Beta) then at least the original questioner and respondents would be kept in the loop. – Drew Oct 10 '14 at 15:00
  • @Drew: The aim is to have a good place for asking and answering questions about Emacs. All SE sites are encouraged to "seed" the site during (private) beta with good questions and answers, so that later visitors to the site know what kind of content is appropriate. Anyway, I only came here because I heard of this site and thought of asking the questions that were bothering me at the moment; those thoughts about migrating questions were spurred by your remarks in the first comment above. – ShreevatsaR Oct 11 '14 at 3:41
  • OK. Please take it to Meta, if you have something more to say. – Drew Oct 11 '14 at 5:55

The anzu package does that.

anzu.el provides a minor mode which displays current match and total matches information in the mode-line in various search modes.


| improve this answer | |
  • Thanks! I added MELPA and installed anzu and turned it on, and it seems to be working. I'll wait to see if anyone else has a solution that doesn't depend on any packages (at least, packages not in ELPA). – ShreevatsaR Oct 9 '14 at 23:13

Here are some possibilities that aren't very slick, that have the advantage of working with a stock Emacs.

If you press M-s o (isearch-occur) during an incremental search, an Occur buffer pops up with the current search expression. At the top of the *Occur* buffer is the number of matching lines.

The command how-many displays the number of occurrences of a regexp (including repeated occurrences). Unfortunately it isn't integrated with incremental search. Here's a proof-of-concept isearch integration: press M-s # during isearch to show the number of matches.

(defun isearch-how-many (regexp)
  "Run `how-many' using the last search string as the regexp.
Interactively, REGEXP is constructed as with `isearch-occur'."
   (list (cond
      ((functionp isearch-word)
       (funcall isearch-word isearch-string))
      (isearch-word (word-search-regexp isearch-string))
      (isearch-regexp isearch-string)
      (t (regexp-quote isearch-string)))))
  (how-many regexp nil nil (interactive-p)))
(define-key isearch-mode-map [?\M-s ?#] 'isearch-how-many)
| improve this answer | |
  • This... yeah. It's not exactly what I want, but it's valuable to know the best that's possible with stock Emacs, thanks. – ShreevatsaR Oct 10 '14 at 0:03
  • This seems only showing the number of matching lines, not number of matches. – xuhdev Apr 25 '17 at 18:03

I would like to suggest Swiper!

Swiper is an alternative to isearch that uses ivy to show an overview of all matches.

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.