dotancohen · 2022-05-23 13:19
When using Evil in Org mode, `Ctrl-Enter` properly starts a new heading. However, it leaves the cursor in Normal mode. How could one configure Emacs to enter Insert mode when pressing `Ctrl-Enter`?
marlgl · 2022-05-23 14:31
`Ctrl-Enter` is bound to `org-insert-heading-respect-content`. You can:
* Define your own function to override the default one:
​
(defun evil-org-insert-heading-respect-content ()
"Call `org-insert-heading-respect-content' and go to insert mode."
(interactive)
(call-interactively 'org-insert-heading-respect-content)
(evil-insert nil))
(evil-define-key 'normal org-mode-map (kbd "C-<return>") #'evil-org-insert-heading-respect-content)
* Advice the default function to switch to insert mode after its execution. This option is naive, since it couples the function and evil logic. You would try to switch to insert mode, even if evil is not even active, for instance.
You might want to redefine also the function `org-insert-todo-heading-respect-content-below`. Instead of re-inventing the wheel, you would be better checking the package [evil-org-mode](https://github.com/Somelauw/evil-org-mode) , that already defines them or a similar one.
nv-elisp · 2022-05-23 19:25
(add-hook 'org-insert-heading-hook (apply-partially #'evil-insert 1))
You could wrap the call to `evil-insert` to be more cautious, but the hook is there for this sort of thing.
dotancohen · 2022-05-24 11:15
Thank you! There is much that I am learning from this.
dotancohen · 2022-05-24 11:21
Perfect, thank you. Dropped that right in and Emacs behaves the way I wanted.