5

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.

juanjux
  • 621
  • 6
  • 15
  • 1
    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 ` to see the function's name. So something like `(define-key evil-normal-state-map "/" 'search-forward)` ? – Ehvince Sep 10 '14 at 16:03
  • 1
    it would be nice seeing you edit this doc if you feel it is too sparse: http://wikemacs.org/index.php/Evil – Ehvince Sep 10 '14 at 16:25
  • @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 Sep 10 '14 at 21:57
  • 1
    Cool, come post the link here ! – Ehvince Sep 11 '14 at 08:11
  • 1
    Made an extension, check my comment on the solution :) – juanjux Sep 18 '14 at 13:37

3 Answers3

3

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

juanjux
  • 621
  • 6
  • 15
2

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)
Tom Wadley
  • 121,983
  • 1
  • 26
  • 29
  • 2
    If I set it up this way, some keys do not work properly i. e. search again (n key) was trying to invoke isearch. For me the solution was to do: `(evil-select-search-module 'evil-search-module 'evil-search)` after `(evil-mode 1)` . – Tahtisilma Oct 12 '16 at 19:31
0

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)
DabeDotCom
  • 121
  • 6