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?

  • Not directly related to the question but the op may not be aware of helm-projectile-on, which may obviate the need to create a custom key binding. – charshep Oct 14 '19 at 15:54
  • Please clarify how helm-projectile-on helps: explain for example how&when to use it and in which sense it makes a keybinding unnecessary. – Stefan Oct 14 '19 at 18:30

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:

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