3

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".

illabout
  • 285
  • 2
  • 14

2 Answers2

3

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:

https://github.com/syl20bnr/spacemacs/blob/b252d252b0e93249b51400f60a0c69a59aa140a4/layers/%2Bspacemacs/spacemacs-editing-visual/packages.el#L173-L177

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)))
illabout
  • 285
  • 2
  • 14
  • 1
    That worked like a charm for me, with the only nagging that the searched term _does not_ populate the search history. Therefore, when you do `/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. – Jir Sep 20 '18 at 14:07
2

Evil-visualstar is a package that provides the feature, but I am not sure of the compatibility with spacemacs.