1

Let's say I have the following org file:

* level 1
** level 2.1
*** level 3.1.1
**** level 4.1.1.1
**** level 4.1.1.2
*** level 3.1.2
**** level 4.1.2.1
**** level 4.1.2.2
** level 2.2
*** level 3.2.1
**** level 4.2.1.1
**** level 4.2.1.2
*** level 3.2.2
**** level 4.2.2.1
**** level 4.2.2.2

If I fold my file completely I'll see:

enter image description here

Then if I press tab once I see:

enter image description here

And if I press tab twice I'll have:

enter image description here

I'd like to change the tab behavior of the second tab press. On the second press, it opens all levels of my tree, I want it to open only the second level of my tree as the following:

enter image description here

This way it'd never open all the tree at once... My guess is that there's an elisp function somewhere that I can change, but I don't know how to find it... How can I change the tab behavior to make it open only the second level on the second press?

1 Answer 1

1

This is built-in to Org mode: S-TAB is bound to org-cycle-global whose doc string says:

Cycle the global visibility.  For details see ‘org-cycle’.
With ‘C-u’ prefix ARG, switch to startup visibility.
With a numeric prefix, show all headlines up to that level.

As the last sentence indicates, you can see all headlines up to e.g. level 3, by saying C-u 3 S-TAB. Replacing the 3 with another number will show you headlines with level up to (and including) that number.

BTW, TAB does subtree cycling; S-TAB does global cycling: see the Global and local cycling section of the Org mode manual for details. In your case above, you have a single level 1 headline, so the two are identical, but in general, this is not going to be the case.

1
  • Cool, it's a little different from what I had initially thought since C-u number S-TAB opens all the tree and not only the topic that is under the cursor, but it works fine for what I need. Thanks!
    – raylight
    Commented Nov 25, 2022 at 14:45

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.