In Spacemacs, is there an easy way to make * (which calls the function spacemacs/enter-ahs-forward
) work like it does in Vim?
That is, I want * to perform forward searching like in Vim, without opening up the "Symbol Highlight Transient State".
After some searching I have figured this out.
Evil actually already has the search-forward functionality just like vim. Here is where the mapping to * is defined:
https://github.com/emacs-evil/evil/blob/427cf5faa57e8794ac93f594dc3d1972e687a25a/evil-maps.el#L232
However, it appears that spacemacs overrides this mapping:
Spacemacs is using use-package
to load the auto-highlight-symbol
package, and in the :config
section it is overwriting the mapping for *.
So in order to overwrite this mapping, it is neccesary to call define-key
after auto-highlight-symbol
has already been loaded. The following code can be put in your .spacemacs
file:
(defun dotspacemacs/user-config ()
(with-eval-after-load 'auto-highlight-symbol
(define-key evil-motion-state-map (kbd "*") 'evil-search-word-forward)))
The following can be used if you want to overwrite both forward search and backward search:
(defun dotspacemacs/user-config ()
(with-eval-after-load 'auto-highlight-symbol
(define-key evil-motion-state-map (kbd "*") 'evil-search-word-forward)
(define-key evil-motion-state-map (kbd "#") 'evil-search-word-backward)))
/a
, position yourself over another word, say "bbb" and hit *
, the next time you hit n
you'll search for "a". I'll probably turn this into a question.
Evil-visualstar is a package that provides the feature, but I am not sure of the compatibility with spacemacs.