5
votes

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.

2
congrats for the jump ! I didn't find an option. At least you could remap the / key to the builtin non-incremental search. See C-h k <your key> to see the function's name. So something like (define-key evil-normal-state-map "/" 'search-forward) ?Ehvince
it would be nice seeing you edit this doc if you feel it is too sparse: wikemacs.org/index.php/EvilEhvince
@Ehvince thanks for the tip, I did it. I'll check Evil's source to see if there is a way to have what I want. I'm writing an article about the settings I'm changing and I'll publish it soon, I'll check that wiki too to see if I can add something useful.juanjux
Cool, come post the link here !Ehvince
Made an extension, check my comment on the solution :)juanjux

2 Answers

3
votes

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

2
votes

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)