I am trying to avoid elisp as much as possible. I think I am able to implement a solution to my problem in Elisp, but that's not what I am looking for.
I am looking for the nth occurence of a string in a buffer.
For instance looking after the 4th occurence of foo
, I've tried C-u C-s foo
. But C-s
does not interpret prefixes.
Is there a simple/elegant key sequence in Emacs to perform that job?
search-forward
is a simple function to search the next occurrence of a string. It also accepts an optional COUNT
argument searching for the next COUNT
successive occurrences.
Unfortunately you cannot call it with a prefix argument, because it queries for input.
You already guessed the answer: throw together some elisp.
This function queries you for a string and a count and performs the search:
(defun search-forward-count (string count)
(interactive "sString: \nnCount: ")
(re-search-forward string nil nil count))
This function queries you for a string and uses the prefix argument as its count:
(defun search-forward-prefix (count string)
(interactive "p\nsString: ")
(re-search-forward string nil nil count))
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