How to look for the nth appearance of a pattern in Emacs?

I try to avoid elisp as much as possible. I think I can implement a solution to my problem in Elisp, but that is not what I am looking for.

I am looking for the nth occurrence of a string in a buffer. For example, after the 4th appearance foo, I tried C-u C-s foo. But C-sdoes not interpret prefixes.

Is there a simple or elegant key sequence in Emacs to do the job?

+4
source share
1 answer

search-forward- A simple function to search for the next occurrence of a string. It also accepts an optional argument COUNTthat looks for the next COUNTconsecutive occurrences.

, , .

: elisp.

:

(defun search-forward-count (string count)
  (interactive "sString: \nnCount: ")
  (re-search-forward string nil nil count))

:

(defun search-forward-prefix (count string)
  (interactive "p\nsString: ")
  (re-search-forward string nil nil count))
+6

Source: https://habr.com/ru/post/1534820/


All Articles