Use 'execute-extended-command' from Evil command mode (M-x is undefined)

穿精又带淫゛_ 提交于 2019-12-23 19:23:49

问题


I just started experimenting with emacs. And as a Vim user I did not want to bother use it without installing evil-mode first.

However, evil-mode seems to break the emacs keybinding for 'execute-extended-command' (M-x).

I really don't care about this keybinding, and I noticed that I can call for example 'list-packages' from the evil command-mode and it works just fine. Only thing I am missing now, is the TAB auto completion in command mode, like typing 'list-' TAB and then it will show or iterate available commands. Is this possible with evil-mode?

or is there eventually an easy way to fix this keybinding?

I am using:

  • debian jessie
  • GNU Emacs 24.4.1

EDIT:

My .emacs file:

(require 'package)
(push '("marmalade" . "http://marmalade-repo.org/packages/")
    package-archives )
(push '("melpa" . "http://melpa.milkbox.net/packages/")
    package-archives)

(add-to-list 'load-path "~/.emacs.d/evil")
(require 'evil)
(evil-mode 1)

(define-key evil-normal-state-map [escape] 'keyboard-quit)
(define-key evil-visual-state-map [escape] 'keyboard-quit)
(define-key minibuffer-local-map [escape] 'minibuffer-keyboard-quit)
(define-key minibuffer-local-ns-map [escape] 'minibuffer-keyboard-quit)
(define-key minibuffer-local-completion-map [escape] 'minibuffer-keyboard-quit)
(define-key minibuffer-local-must-match-map [escape] 'minibuffer-keyboard-quit)
(define-key minibuffer-local-isearch-map [escape] 'minibuffer-keyboard-quit)

I attempted to add Modifier-x

(global-set-key (kbd "C-x") 'execute-extended-command)

and Alt-x

(global-set-key (kbd "A-x") 'execute-extended-command)

but these attempts didn't fix the keybinding, so I've decided to roll with super key

(global-set-key (kbd "s-x") 'execute-extended-command)

回答1:


Fixing keyboard bindings is quite easy - just add this line to your .emacs file (or evaluate it in the scratch buffer):

(global-set-key (kbd "< put your key combination here >") 'execute-extended-command)

You can use reference from ErgoEmacs to understand how to provide key combinations for kbd function.

And IMO it's better to use standard Emacs means to run commands - use your evil-mode command mode for evil-related things, and use M-x/execute-extended-command to work with Emacs.



来源:https://stackoverflow.com/questions/28703740/use-execute-extended-command-from-evil-command-mode-m-x-is-undefined

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!