Reputation: 641
I'm trying Emacs+Evil after almost two decades as a Vim user. I'm moving most of my Vim configuration to Evil but one thing that I'm having a lot of problems is to set the search and highlighting like the one I use with Vim. What I'm trying to get is to have non-incremental search and the highlights to remain until I clear them manually or make another search.
I've set these settings on my config file:
;; keep the search highlights
(setq lazy-highlight-cleanup nil)
(setq lazy-highlight-max-at-a-time nil)
(setq lazy-highlight-initial-delay 0)
Using the /
key to search with Evil does the incremental thing and also the highlights are removed as soon as I press any other movement key (like j
key but with C-s
(emacs internal i-search) the highlights remain. With C-s RET
(non incremental search) the highlights doesn't remain.
Upvotes: 6
Views: 2611
Reputation: 121
I know it's an old question, but it came up as the first hit on Google, and I just wanted to add...
You can disable incremental searching altogether with:
(setq evil-ex-search-incremental nil)
Upvotes: 0
Reputation: 121853
To make '/' search work like it does in vim (highlight persists until you search again), put this before you (require 'evil)
:
(setq evil-search-module 'evil-search)
Upvotes: 3
Reputation: 641
Ok, found a working solution for the highlighting:
(defun highlight-remove-all ()
(interactive)
(hi-lock-mode -1)
(hi-lock-mode 1))
(defun search-highlight-persist ()
(highlight-regexp (car-safe (if isearch-regexp
regexp-search-ring
search-ring)) (facep 'hi-yellow)))
(defadvice isearch-exit (after isearch-hl-persist activate)
(highlight-remove-all)
(search-highlight-persist))
(defadvice evil-search-incrementally (after evil-search-hl-persist activate)
(highlight-remove-all)
(search-highlight-persist))
This will highlight all searches done with isearch or Evil search. The highlight will remain until you make another one or call highlight-remove-all
. I've mapped it to leader SPC
with:
(evil-leader/set-key "SPC" 'highlight-remove-all)
PS: I made a package, it's already on melpa with the name "evil-search-highlight-persist" and: https://github.com/juanjux/evil-search-highlight-persist
Upvotes: 3