I want to emulate a behavior I've had in vim, but in emacs evil-mode. I want *
to search for the current visually selected text. The code below sort of works, but pressing n
or N
does not retain the search string
(define-key evil-visual-state-map (kbd "*")
(lambda () (interactive)
(let ((search-string (buffer-substring
(evil-range-beginning (evil-visual-range))
(evil-range-end (evil-visual-range)))))
(evil-normal-state)
(evil-search search-string t))))
I'm new to emacs/elisp. Any ideas on what the "right way" to do this is? In the evil-search.el source I see a function evil-ex-search-update-pattern
that may be useful, but I'm not sure how to put it together.
Thanks!