Search code examples
emacsevil-mode

properly editing a shell buffer with evil-mode


I'm using evil-mode. When I type M-x multi-term zsh opens up.

I then type bcdef in the terminal. Then I hit ESC to enter normal mode, then b so my cursor is place on b of the bcdef word. Then I hit i to enter insert mode and then I type a to insert an a.

Instead of inserting the a where I wanted, emacs inserts the a in the end of the word.

What is happening? how do I achieve the desired normal behaviour?

this only happens in shell buffers.


Solution

  • You have to produce an ESC that is eaten by the terminal but not by emacs/evil. If you just press ESC, then emacs/evil will eat the ESC and not send the ESC to the terminal.

    You can produce an ESC that is eaten by the terminal, but not emacs, by hitting C-C C-E in emacs-mode. Here is what C-h k tells me:

    C-c C-e runs the command term-send-esc (found in term-raw-map), which
    is an interactive compiled Lisp function in
    ‘~/code/sources/dotfiles/emacs/elpa/multi-term-20160619.233/multi-term.el’.
    
    It is bound to C-c <escape>, C-c C-e, <emacs-state> C-c <escape>.
    
    (term-send-esc)
    
    Send ESC in term mode.