Evil Emacs:有没有办法在«insert»模式下禁用类似vim的键?

时间:2014-10-26 11:59:50

标签: plugins emacs configuration editor elisp

我喜欢VIM对文本对象的看法,所以我安装了EVIL (一个Emacs插件来模拟VIM功能)。但我希望«insert»模式让Emacs键绑定不变(除了 Escape ,这将切换到«normal»模式)。有没有办法实现这个目标?

顺便说一句:ATM«insert»模式有一组混合的热键,无论哪种方式都不太舒服。例如。 «M-b»在Emacs中起作用,但«C-o»在VIM中起作用。

1 个答案:

答案 0 :(得分:3)

#emacs IRC频道中,我被告知someone already solved a similar problem。这是我使用的修改版本:

(require 'evil)
;; remove all keybindings from insert-state keymap
(setcdr evil-insert-state-map nil)
;; but [escape] should switch back to normal state
(define-key evil-insert-state-map [escape] 'evil-normal-state)
(define-key evil-normal-state-map (kbd "C-u") 'evil-scroll-up)
(define-key evil-normal-state-map (kbd "[ m") 'beginning-of-defun)
(define-key evil-normal-state-map (kbd "] m") 'end-of-defun)
(define-key evil-normal-state-map (kbd "k") 'evil-previous-visual-line)
(define-key evil-normal-state-map (kbd "j") 'evil-next-visual-line)

(evil-mode t)
(setq evil-jumps-cross-buffers nil) ;; for C-o and C-i to not cross buffers
(provide 'emvil)

(provide 'emvil)是允许在配置中require '。我还发现在下一个分屏中跳转到定义是有用的,除非定义在我当前所在的缓冲区中。这里是代码:

(defun evil-goto-definition-next-split ()
    "If there's a free split, goto definition in this split,
    otherwise use current one (except when a definition in the
    current split)"
    (interactive)
    (let ((origin-spl (selected-window))
          (origin-buf (current-buffer)))
      (evil-goto-definition)
      (when (and (eq origin-spl (selected-window)) ;; otherwise it's done
                 (not (eq origin-buf (current-buffer)))) ;; otherwise either definition not found, or
                                                         ;; it's in the same buffer
        (let ((defin-buf (current-buffer))
              (defin-point (point)))
          (switch-to-buffer origin-buf)
          (other-window 1)
          (switch-to-buffer defin-buf)
          (goto-char defin-point)
          ))
      ))
(define-key evil-normal-state-map (kbd "g d") 'evil-goto-definition-next-split)