快捷键设置写入配置后,重启运行出错。

*scratch*中运行如下代码,均设置成功,但是将这些设置都写入配置文件以后哦,重启发现报错且没有效果,请问如何解决?谢谢!

这是我的设置:

(define-key evil-insert-state-local-map "\C-a" 'move-beginning-of-line)
(define-key evil-insert-state-local-map "\C-e" 'move-end-of-line)
(define-key evil-normal-state-local-map "\C-a" 'move-beginning-of-line)
(define-key evil-normal-state-local-map "\C-e" 'move-end-of-line)

报错信息是:

/mirasire/.emacs.d/lisp/init-keybindings.el" "/home/mirasire/.emacs.d/lisp/init-keybindings.el" nil t)
  require(init-keybindings)
  eval-buffer(#<buffer  *load*> nil "/home/mirasire/.emacs.d/init.el" nil t)  ; Reading at buffer position 293
  load-with-code-conversion("/home/mirasire/.emacs.d/init.el" "/home/mirasire/.emacs.d/init.el" t t)
  load("/home/mirasire/.emacs.d/init" t t)
  #f(compiled-function () #<bytecode 0x1df6a1>)()
  command-line()
  normal-top-level()

版本是emacs26.3 。

emacs --debug-init启动 ,然后再来贴报错信息。 你这报错信息太简陋了。

盲猜,你这个require init keybinding 写在evil加载之后了吗?

keybinding一般要写在加载之后,因为一般不autoload keymap

(with-eval-after-load 'evil
  (define-key evil-insert-state-local-map "\C-a" 'move-beginning-of-line)
  (define-key evil-insert-state-local-map "\C-e" 'move-end-of-line)
  (define-key evil-normal-state-local-map "\C-a" 'move-beginning-of-line)
  (define-key evil-normal-state-local-map "\C-e" 'move-end-of-line))
1 个赞

后来发现是evil-insert-state-local-map的问题,只要将其中的-local去掉,就设置正常了。

(with-eval-after-load 'evil
  (define-key evil-insert-state-map (kbd "C-a") 'move-beginning-of-line)
  (define-key evil-insert-state-map (kbd "C-e") 'move-end-of-line)
  (define-key evil-normal-state-map (kbd "C-a") 'move-beginning-of-line)
  (define-key evil-normal-state-map (kbd "C-e") 'move-end-of-line))