3

I like VIM idea of text objects, so I installed EVIL (a Emacs plugin to emulate VIM features). But I'd like «insert» mode to leave Emacs keybindings unchanged (except perhaps Escape which is to switch into «normal» mode). Any way to achieve this?

By the way: ATM «insert» mode have a mixed set of hotkeys, which isn't very comfortable either way. E.g. the «M-b» works as in Emacs, but the «C-o» works as in VIM.

0

1 Answer 1

4

In the #emacs IRC channel I was told that someone already solved a similar problem. Here's the modified version I use:

(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) 

The (provide 'emvil) is to allow require 'ing it in the configuration. I also found it useful to jump-to-definition in the next split screen unless the definition is in the buffer I'm currently in. Here's the code:

(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) 
Sign up to request clarification or add additional context in comments.

6 Comments

Hm, I got it. Sometimes (I can't yet tell on what is it depends) the EVIL changes list in the variable «global-map». Hm…
Ah, I got it. The (define-key evil-insert-state-map (kbd "<ESC>") 'evil-normal-state) somehow brokes all a keybindings, although should only touch the Escape key.
I finally found… I have no idea what the difference, but the only works is (define-key evil-insert-state-map [escape] 'evil-normal-state)
Just if anybody curious, I have at the present moment this in my Emacs: (evil-mode) (setq evil-insert-state-map global-map) (define-key evil-insert-state-map [escape] 'evil-normal-state) (global-set-key (kbd "C-S-z") 'undo-tree-redo)
There is some new property set: evil-disable-insert-state-bindings But can't find the way to enable it
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.