CrabMan
CrabMan

Reputation: 1758

How to keep traditional binding on M-x in emacs evil mode

I am trying to bind execute-extended-command to M-x in evil normal mode. I currently have

;; evil mode
(require 'evil)
(evil-mode 1)

(define-key evil-normal-state-map "M-x" 'execute-extended-command)

in my .emacs file but the keybinding doesn't work. I tried replacing

"M-x"

with

"\M-x"

and

(kbd "M-x")

but neither works. I also tried adding it to evil.el and evil-maps.el.

Upvotes: 3

Views: 2641

Answers (2)

CrabMan
CrabMan

Reputation: 1758

After long research and with help from #emacs and #evil-mode channels on irc, it turned out that my emacs was broken. It was a snapshot from http://emacs.naquadah.org/ I tried all this on another emacs version (from debian jessies repos) and it worked ok.

Upvotes: 0

mike3996
mike3996

Reputation: 17517

I don't know what's wrong with your binding. You could use Emacs' own global-set-key for global stuff and if you plan something special for say, insert mode, you could override that later on, like this:

 ;; this works, just tested. My evil is 1.0-dev from github.
 (global-set-key (kbd "M-x") 'smex)
 (define-key evil-insert-state-map (kbd "M-x") 'execute-extended-command)

Use (kdb "") macro when you have modifier keys in your binding. But you can use the macro always, regardless of the content. These are for example usage. When in doubt, wrap the key in (kdb ).

 (global-set-key (kbd "M-x") 'smex)
 (global-set-key (kbd "M-X") 'smex-major-mode-commands)
 ;;(global-set-key (kbd "M-x") 'execute-extended-command)

 (define-key evil-normal-state-map ",d" 'volatile-kill-buffer)
 (define-key evil-normal-state-map ",b" 'ido-switch-buffer)
 (define-key evil-normal-state-map ",s" 'ispell-word)

 (define-key evil-normal-state-map (kbd "C-x g") 'magit-status)
 (define-key evil-insert-state-map (kbd "C-f") 'my-expand-file-name-at-point)
 (define-key evil-insert-state-map (kbd "C-x C-l") 'my-expand-lines)

 (define-key minibuffer-local-map (kbd "C-w") 'backward-kill-word)
 (define-key evil-normal-state-map (kbd ",ff") 'ido-find-file)

Upvotes: 1

Related Questions