How can I override the org-mode indentation function of TAB in evil-insert-state-map? I'd like it to always fold and unfold the current or parent header, and switch the indentation functionality to another keybinding.

  • What is the output of C-h k while under evil-insert-state in org-mode?
    – TerryTsao
    May 19, 2021 at 5:17
  • org-cycle. Interesting... Why isn't the visibility cycling, then...? May 19, 2021 at 5:22
  • Found why. Please see below.
    – TerryTsao
    May 19, 2021 at 6:00

1 Answer 1


From the doc of org-cycle:

When point is not at the beginning of a headline, execute the global
binding for `TAB', which is re-indenting the line.  See the option
`org-cycle-emulate-tab' for details.

Seems setting org-cycle-emulate-tab to nil will do.

Relevant doc:

Where should ‘org-cycle’ emulate TAB.
nil         Never
white       Only in completely white lines
whitestart  Only at the beginning of lines, before the first non-white char
t           Everywhere except in headlines
exc-hl-bol  Everywhere except at the start of a headline
If TAB is used in a place where it does not emulate TAB, the current subtree
visibility is cycled.

Relevant code:

Note how when everything fails, fallback to cycle the headings (Last 4 lines).


       ((or (eq org-cycle-emulate-tab t)
        (and (memq org-cycle-emulate-tab '(white whitestart))
             (save-excursion (beginning-of-line 1) (looking-at "[ \t]*"))
             (or (and (eq org-cycle-emulate-tab 'white)
                  (= (match-end 0) (point-at-eol)))
             (and (eq org-cycle-emulate-tab 'whitestart)
                  (>= (match-end 0) pos)))))
        (call-interactively (global-key-binding (kbd "TAB"))))
  • Huh... Actually, in insert mode, it's still indenting the headers. Can I change that as well? May 19, 2021 at 6:28
  • @ShadowRylander That's weird. Setting nil works for me. I don't have doom emacs to dig further unfortunately.
    – TerryTsao
    May 19, 2021 at 6:40
  • Ah, fair enough; thank you kindly for the help either way! May 19, 2021 at 6:56
  • @ShadowRylander Actually, have you ever tried edebug? Source code of org-cycle isn't that long to track. Perhaps you can find which cond condition is the culprit. It's what I would do if I were to have this problem.
    – TerryTsao
    May 19, 2021 at 7:48
  • I was thinking more along the lines of attaching org-cycle to a keychord; if that tabs as well, I'll know for sure it's the org-cycle function itself. From there I could just use edebug, as you mentioned. May 19, 2021 at 11:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.