1

I am trying to bind C-n and C-p to call next-buffer and previous-buffer. They seem to conflict with some evil-mode key bindings and I don't seem to be able to overwrite them. When I press them I get

Previous command was not evil-paste: evil-paste-pop

and

Previous command was not evil-paste: evil-paste-pop-next

for C-n and C-p respectively

In my .emacs file I have the following:

(global-unset-key (kbd "C-n"))
(global-set-key (kbd "C-n") 'next-buffer)
(global-unset-key (kbd "C-p"))
(global-set-key (kbd "C-p") 'previous-buffer)

The calls to global-unset-key were added as an attempt to resolve this issue, but to no avail.

1

Unbinding a key requires the correct keymap to work. You can look up Evil's keybindings in evil-maps.el with M-x find-library. The following snippet unbinds both keys:

(with-eval-after-load 'evil-maps
  (define-key evil-normal-state-map (kbd "C-n") nil)
  (define-key evil-normal-state-map (kbd "C-p") nil))

You can then bind both keys globally to something else and they will no longer be intercepted by Evil.

1

The following should work in all evil-mode states:

(evil-define-key
  '(normal insert visual replace operator motion emacs)
  'global
  (kbd "C-n") 'next-buffer)

(evil-define-key
  '(normal insert visual replace operator motion emacs)
  'global
  (kbd "C-p") 'previous-buffer)

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.