emacs-evil / evil-surround

you will be surrounded (surround.vim for evil, the extensible vi layer)
Other
627 stars 60 forks source link

Overriding `s` keybinding? #116

Closed rieje closed 7 years ago

rieje commented 7 years ago

I want to override the s keybinding which is bound to evil-surround-edit in evil's operator state to rebind it to evil-avy-goto-char. I have the following but it still doesn't work:

(evil-define-key 'operator global-map (kbd "s") #'evil-avy-goto-char)

According to an evil maintainer, evil-surround does some hackery to get the bindings to work. How can I override the s key?

ninrod commented 7 years ago

try to not activate the evil-surround minor mode. and see if it works.

rieje commented 7 years ago

I'm not sure why there isn't a function for M-x to execute but I pasted (turn-off-evil-surround-mode) into the buffer, evaluated the sexp, and then it works.

Also, if I changed the binding from s to something that isn't used by evil-surround like o then it also works.

ninrod commented 7 years ago

there you go.

rieje commented 7 years ago

Sorry if noob question, but what makes evil-surround's s prioritize over my attempt to rebind it to something else? And how can I rebind s to something else for evil-surround?

ninrod commented 7 years ago

no problem. I am a huge noob in elisp.

I think the hack comprises this snippet, combined with this snippet.

I'd guess that you could change the minor mode binding in the second snippet to another key, say, r. So evil-surround would be called with yr. then you could free up s to your liking.

I'd go with that for my first try.

rieje commented 7 years ago

Thanks. I have the following now and it works:

(evil-define-key 'operator evil-surround-mode-map "r" 'evil-surround-edit)
(evil-define-key 'operator evil-surround-mode-map "s" nil)
(evil-define-key 'operator global-map (kbd "s") #'avy-goto-char-timer)

If anyone knows a more concise or simpler way to achieve the same thing, I'd love to know.