evil-mode: How to automatically switch to insert mode after certain commands?

Óscar Fuentes ofv at wanadoo.es
Thu Mar 19 17:17:27 CET 2015


max6166 <max6166 at hotmail.com> writes:

> There are many emacs commands after which I almost always immediately want
> to insert text. This often requires entering insert mode after the initial
> command.
>
> Is there any way to instead enter insert mode automatically after certain
> commands?
>
> For example, in org-mode, a user will usually enter some text immediately
> after the commands org-insert-heading or org-capture. 
>
> Though this only requires typing <i>, the situation arises so many times in
> a day that I find myself wishing I could eliminate that extra key press.
>
> What would be the recommended way to do this? 
>
> Incidentally, I am also using evil-org-mode. 

I would try adding a function to `post-command-hook' that enters
instert-mode when `insert-command' is in a list of symbols.

Totally untested code:

(defvar maybe-enter-insert-mode-commands
  '(org-insert-heading)
  "List of commands that trigger insert mode.")

(defun maybe-enter-insert-mode ()
  (when (memq last-command maybe-enter-insert-mode-commands)
     (evil-insert-state nil)))

(add-hook post-command-hook 'maybe-enter-insert-mode)




More information about the implementations-list mailing list