2

I found this function in this site:

(defun search-selection (beg end)
  "search for selected text"
  (interactive "r")
  (let ((selection  (buffer-substring-no-properties beg end)))
    (deactivate-mark)
    (isearch-mode t nil nil nil)
    (isearch-yank-string selection)))

(define-key global-map (kbd "<C-f3>") 'search-selection)

With this, I just need to select the text and hit C-f3, and Isearch finds the string from the current cursor point to the rest of the buffer. But when it reaches the bottom the function doesn't wrap around to search from the beginning of the buffer.

How can I make this function wrap around?

  • 1
    It works OK for me. Did you use C-s to repeat the search? – Drew Apr 26 '18 at 0:00
  • You're right, I was pulsing C-f3. – aarkerio Apr 27 '18 at 17:28
5

It works OK for me. Did you use C-s to repeat the search?

C-s repeats Isearch, including to wrap around.


You can replace the repeat-search binding:

(define-key isearch-mode-map (kbd "<C-f3>") 'isearch-repeat-forward)

;; Define <C-M-f3> similarly so you can use it to repeat regexp Isearches.
(define-key isearch-mode-map (kbd "<C-M-f3>") 'isearch-repeat-forward)

You can also do the same kind of thing for isearch-repeat-backward.

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.