Emacs + Evil: non-incremental search and constant highlighting?

I have been trying Emacs + Evil after almost two decades to be a Vim user. I am moving most of my Vim configuration to Evil, but one thing I am having a lot of problems with is setting the search and highlight like the one I use with Vim. What I am trying to get is that the non-incremental search and the main points remain until I cleaned them manually or performed another search.

I set these parameters in the configuration 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, the incremental thing, as well as the highlights, are deleted as soon as I press any other navigation key (like j ), but with Cs (emacs internal i-search) the highlight remains. With Cs RET (without incremental search), backlighting does not remain.

+5
source share
2 answers

Ok, found a working solution for 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 display all searches made using isearch or Evil. The selection remains until you do another or call highlight-remove-all . I matched it with leader SPC using

 (evil-leader/set-key "SPC" 'highlight-remove-all) 

PS: I made a package, it is already on melpa with the name "evil-search-highlight-persist" and: https://github.com/juanjux/evil-search-highlight-persist

+3
source

To make the search "/" work like in vim (the highlight remains until you search again), put this before you (require 'evil) :

 (setq evil-search-module 'evil-search) 
+1
source

Source: https://habr.com/ru/post/1202247/


All Articles