2

In org mode I go to a subtree. This subtree contains lots of text, let's say a thousand lines. I want to look up some information in it. I got it, but now I want to collapse that subtree I'm in directly with a keystroke. That's all. But it seems that I need to go with the cursor to the heading before I can use TAB for visiblity cycling. Jumping to the heading takes time and is tedious. When I use TAB inside the subtree text nothing happens and I haven't found any other way to collapse the subtree directly.

I looked at the manuals and internet but I couldn't find any solution. Stackexchange is my last resort. Since I'm not a coder I can't help myself here programming a lisp function to solve the problem. Additonally I think this is useful also for other users and I would have needed it very often myself.

3

Something like this ?

(defun my-cycle-previous-heading ()
  (interactive)
  (outline-previous-heading)
  (org-cycle))

(define-key org-mode-map (kbd "C-x C-l") 'my-cycle-previous-heading)
  • Perfect, thank you so much. The other solutions deserve credit too, but they involve an intermediate step. I need this daily and often, so I go with your custom function.Though I changed the the keybinding to "C-c d" to be in line with the other org fuctions. – Jens Lange Oct 19 '16 at 11:51
3

The Org manual section 2.4 Motion describes the key bindings to be used for navigation.

For your case I think

 C-c C-p   (outline-previous-visible-heading)  
                 Previous heading. 

would cater the requirement. When you are within a sub heading with lots of lines just use C-c C-p to navigate to the heading and press the Tab key to collapse the heading.

  • 1
    Your solution is nearly as good as the custom function solution. Thanks for showing the relevant section in the manual. I don't know why I overlooked it, it might be the function name that is not so clear to me. – Jens Lange Oct 19 '16 at 12:06
2

C-u <tab> (#'org-cycle) will collapse all top-level trees. This might or might not be what you want.

Alternately, you can move up to the parent heading (repeating it to go more than one level up) with C-c C-u (#'outline-up-heading), and then press tab to collapse it.

  • Neither I want to collapse all level nor I want to go up a heading. It works when going up a heading, collapsing it, opening it and then going down to the heading below. It would be still faster than going manually up and collapsing it but the solutions above are more fitting. Thanks for looking at the issue anyway. – Jens Lange Oct 19 '16 at 12:12
  • @phils that was meant to be <kbd>C-u &lt;tab&gt;</kbd>, but I forgot that the parser would treat <tab> as an html entity. Fixed now, thanks. – zck Oct 19 '16 at 18:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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