hlissner/evil-snipe

Moving mouse ends evil-snipe search

gilbertw1 opened this issue · 4 comments

Hi, I'm finding evil-snipe invaluable during my day to day programming. However, one continued problem I keep running into is the fact that moving the mouse at all will end the current search and pressing 's' will start a new one instead of cycling through the next occurances.

This is a problem for me as I bump my trackpad frequently while I'm working and the minute mouse movement frequently ends the search for me prematurely resulting in a new accidental search for 'ss'. Is there any way for evil-snipe to ignore mouse movement or disable this behavior?

I am using Spacemacs with the evil-snipe layer enabled. Thank you!

Thank you for the kind words!

I can see how that would be annoying. Unfortunately this wouldn't be trivial to fix.

I can offer two workarounds while I look into it. First, after clicking the mouse, you can press C-o to jump back to where you started before the last snipe, and then s + Enter to repeat the last snipe.

Alternatively (and this is what I use):

(defmacro def-repeat! (command next-func prev-func)
  "Repeat motions with SPC/S-SPC"
  `(defadvice ,command
       (before ,(intern (format "doom-space--%s" (symbol-name command))) activate)
     (define-key evil-motion-state-map (kbd "SPC") ',next-func)
     (define-key evil-motion-state-map (kbd "S-SPC") ',prev-func)))

(def-repeat! evil-snipe-f evil-snipe-repeat evil-snipe-repeat-reverse)
(def-repeat! evil-snipe-F evil-snipe-repeat evil-snipe-repeat-reverse)
(def-repeat! evil-snipe-t evil-snipe-repeat evil-snipe-repeat-reverse)
(def-repeat! evil-snipe-T evil-snipe-repeat evil-snipe-repeat-reverse)
(def-repeat! evil-snipe-s evil-snipe-repeat evil-snipe-repeat-reverse)
(def-repeat! evil-snipe-S evil-snipe-repeat evil-snipe-repeat-reverse)
(def-repeat! evil-snipe-x evil-snipe-repeat evil-snipe-repeat-reverse)
(def-repeat! evil-snipe-X evil-snipe-repeat evil-snipe-repeat-reverse))

With this, I can turn off evil-snipe's repeat keys and just use SPC/S-SPC to repeat motions universally. def-repeat can be applied to any other motion too, like incremental search:

(def-repeat! evil-ex-search-next evil-ex-search-next evil-ex-search-previous)
(def-repeat! evil-ex-search-previous evil-ex-search-next evil-ex-search-previous)
(def-repeat! evil-ex-search-forward evil-ex-search-next evil-ex-search-previous)
(def-repeat! evil-ex-search-backward evil-ex-search-next evil-ex-search-previous)

I hope that helps!

Thanks for taking the time to respond, I really appreciate it!

I'll check out the above suggestions and see which one works best for me. I did find one other work around I've been trying, which is to repeat the search using ';' versus 's'. It only works one direction, but is pretty simple. Thanks again!

I take it you've rebound , as your leader key? If not, , is the "reverse" of ;.

; and , will always repeat snipes. It's just that most people (myself included) tend to rebind those two keys.

Ah so it is! (I'm a recent spacemacs convert, so I'm still a newbie) That works outs nicely....thanks!