is it possible to replace Insert state with Emacs state?
Hi, When in Insert state, some Emacs-state key bindings are shadowed in evil, it is annoyed as I used to emacs edit command. Is it possible to enter the emacs state when I press "O","o","i","I" etc in Normal state. Thanks
I wrote some helper code to do this. I'm not sure if it's a good idea, since it makes me want to stick to my old Emacs habits instead of learning Evil commands, but I'm using it anyhow. I also provide a function to toggle this behavior on and off (per buffer), for when insert state is really needed (e.g. when inserting rectangular blocks). Here's the code: #+begin_src emacs-lisp ;; switch to emacs mode instead of insert mode (defadvice evil-append (after evil-append/emacs-state activate) (evil-backward-char) (evil-emacs-state) (forward-char)) (defadvice evil-append-line (after evil-append-line/emacs-state activate) (evil-emacs-state) (end-of-line)) (defadvice evil-insert (after evil-insert/emacs-state activate) (let ((old-point (point))) (evil-emacs-state) (unless (eq old-point (point)) ; that is, if switching to emacs state moved cursor back (forward-char)))) (defadvice evil-insert-line (after evil-insert-line/emacs-state activate) (evil-emacs-state)) (defadvice evil-open-below (after evil-open-below/emacs-state activate) (evil-emacs-state)) (defadvice evil-open-above (after evil-open-above/emacs-state activate) (evil-emacs-state)) (defvar lva-emacs-state-toggle 1 "Keeps the state of how the buffer was last toggled.") (make-variable-buffer-local 'lva-emacs-state-toggle) (defun lva-toggle-emacs-state-advice () (interactive) (let ((evil-insert-advice-regexp "evil-.+/emacs-state")) (if lva-emacs-state-toggle (ad-disable-regexp evil-insert-advice-regexp) (ad-enable-regexp evil-insert-advice-regexp)) (setq lva-emacs-state-toggle (not lva-emacs-state-toggle)) (ad-activate-regexp evil-insert-advice-regexp) (if lva-emacs-state-toggle ; V->E (evil-emacs-state) ;; else E->V (evil-insert-state)))) #+end_src On Thu, Feb 9, 2012 at 10:00 PM, Eric Luo <[email protected]> wrote:
Hi,
When in Insert state, some Emacs-state key bindings are shadowed in evil, it is annoyed as I used to emacs edit command.
Is it possible to enter the emacs state when I press "O","o","i","I" etc in Normal state.
Thanks
_______________________________________________ implementations-list mailing list [email protected] https://lists.ourproject.org/cgi-bin/mailman/listinfo/implementations-list
On Fri, Feb 10, 2012 at 12:00:56PM +0800, Eric Luo wrote:
Hi,
When in Insert state, some Emacs-state key bindings are shadowed in evil, it is annoyed as I used to emacs edit command.
Is it possible to enter the emacs state when I press "O","o","i","I" etc in Normal state.
Replacing insert state with Emacs state completely is probably not a good idea if you want to use functions related with the repeat-system, because this requires some interaction that is only possible with insert-state. This includes the repeat command "." itself but also block or linewise insertion or insertion with count. But perhaps this is not necessary. Insert state is already the state that is closest to Emacs (except for Emacs state itself, of course) and only contains few key-bindings. So if only the shadowing keybindings annoy you I assume the easiest solution might be to remove all additional keybindings from the corresponding keymap: ;; 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) Btw: *all* keybindings defined by evil are in "evil-maps.el" and they are usual Emacs keymaps. It's always a good place to look for something related to keybindings. Hope that works. Frank
On Fri, Feb 10, 2012 at 9:18 AM, Frank Fischer <[email protected]> wrote:
On Fri, Feb 10, 2012 at 12:00:56PM +0800, Eric Luo wrote:
Hi,
When in Insert state, some Emacs-state key bindings are shadowed in evil, it is annoyed as I used to emacs edit command.
(...)
Can't you simply use evil-emacs-state? I have it mapped to C-z here, works well.
On Fri, Feb 10, 2012 at 11:15:24AM +0100, José A. Romero L. wrote:
On Fri, Feb 10, 2012 at 9:18 AM, Frank Fischer <[email protected]> wrote:
On Fri, Feb 10, 2012 at 12:00:56PM +0800, Eric Luo wrote:
Hi,
When in Insert state, some Emacs-state key bindings are shadowed in evil, it is annoyed as I used to emacs edit command.
(...)
Can't you simply use evil-emacs-state? I have it mapped to C-z here, works well.
In fact, it should be mapped to C-z by default. But as I said, using Emacs state will make trouble with the repeat system, i.e., the "dot-command" won't probably work anymore as expected. Frank
,---- | | ;; 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) `---- Thanks, it works like a charm
participants (4)
-
Eric Luo -
Frank Fischer -
José A. Romero L. -
Leo Alekseyev