When I open an org file, I want all the src blocks to start collapsed and stay that way until I explicitly org-cycle them.

I can't find any variable to control this behavior. Perhaps I'm overlooking something? Or maybe someone has an elisp solution?

  • 4
    Here is a link to a related questions that talks about using the variable org-hide-block-startup: stackoverflow.com/a/21563210/2112489. And, the following link has something to do with cycling visibility of src blocks that I wrote up a while back in time, but it doesn't set them to be hidden by default. I won't have time to work on this today or tomorrow, but here is the link in case you or anyone else wants to play a bit with the code: stackoverflow.com/a/25496350/2112489
    – lawlist
    Commented Jan 9, 2015 at 15:10

1 Answer 1


You can achieve what you want by adding the org-hide-block-all command to org-mode-hook:

(add-hook 'org-mode-hook 'org-hide-block-all)

For my personal configuration, I've extended this solution a bit:

(defvar org-blocks-hidden nil)

(defun org-toggle-blocks ()
  (if org-blocks-hidden
  (setq-local org-blocks-hidden (not org-blocks-hidden)))

(add-hook 'org-mode-hook 'org-toggle-blocks)

(define-key org-mode-map (kbd "C-c t") 'org-toggle-blocks)

With this in place, org-mode collapses SRC blocks by default and lets me toggle visibility of all SRC blocks by hitting C-c t. (If you decide to use this code you can of course adapt the key binding to your liking.)

  • i'm looking for a solution that read a metadata and collapses or not by default if metadata says so Commented Jul 17, 2022 at 16:04

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.