2

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

2

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

2

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)))
  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.