1

I put this at the very end of my config file:

(global-set-key (kbd "C-p") 'helm-projectile-find-file)

On Emacs start I can see that it is getting assigned using C-h k C-p. Then when I actually load a project, it gets overwritten and becomes evil-paste-pop

How can I make this to stay set as helm-projectile-find-file?

1

The problem is that minor modes, in this case Evil, take precedence over the global keymap. One solution is to add the binding directly to evil-normal-state-map, as in

(define-key evil-normal-state-map (kbd "C-p") 'helm-projectile)

You can do the same for the insert/visual/etc maps if you'd like.

Alternatively, you can use the bind-key* macro from the bind-key package (should already be installed if you use use-package, Spacemacs, DOOM Emacs, etc.). The asterisk signifies that your binding will not be placed in the global keymap, but instead added to the keymap for bind-key's own override-global-mode (which lives inside emulation-mode-map-alists, whose members take precedence over those in minor-mode-map-alist... sneaky!). Usage is simple:

(bind-key* "C-p" 'helm-projectile)

Finally, you can use the great Swiss Army Knife of keybinding tools, general.el. Something like:

(general-define-key
 :states '(normal insert)
 :keymaps 'override
 "C-p" 'helm-projectile)

This being Emacs, I'm sure there are a million other solutions.

  • For some reason I didn't see your message. Now I made another attempt to use emacs and I run into the same issue. I googled the problem and found this page and then saw your post. This totally works, so thank you very much for this! – Adam Oct 26 '18 at 9:11

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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