I am trying evil mode and want to keep emacs's C-k when in insert mode.

C-k is kill-line

but when smartparens-mode is on, it's sp-kill-hybrid-sexp

So I can't just bind C-k to kill-line in evil-insert-state-map, can I?
(Would smartparens pick up and rebind automatically?)

-- edit

For future reference,

Minor mode key binding > Major mode > Global mode

So more specific mode bindings are used.

In order to override minor mode binding for a major mode,
you need to create a new map that has the new binding and insert into the minor-mode-overriding-map-alist


1 Answer 1


Minor mode keymaps already override the global key map. But I see that evil-insert-state-map is a minor mode map, in which case it can override the other minor modes if it is earlier in the mode list. (See chapter 23.8 Searching the Active Keymaps for a concise description of exactly which keymaps are searched and in what order.) You can use C-h b to get a list of active key maps, and the order they are searched in, for the current buffer.

You could bind C-k to a new command that checks to see if smartparens is enabled, and only calls kill-line if it is not. That won’t scale, but for one command it is simple enough.

A quick check of the evil-mode documentation (C-h i is your friend), shows that if you want to do it right then you should add a hook to evil-insert-state-entry-hook which will check for smartparens mode and enable an additional minor mode containing your keybindings. That way you could bind C-k to kill-line in evil-insert-state-keymap, and then bind it to sp-kill-hybrid-sexp in your new minor mode’s keymap. The new minor mode will be first in the minor mode list, ensuring that it shadows the bindings in the evil-insert-state-keymap. Naturally you would want to remove that minor mode in a hook added to evil-insert-state-exit-hook.

  • Thank you. gnu.org/software/emacs/manual/html_node/emacs/… it might not be accurate but much more accessible. I'm after rebinding it in python-mode not in entire evil-insert-state-keymap. I was able to do it though. by using minor-mode-overriding-map-alist
    – eugene
    Aug 26, 2023 at 12:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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