Q: How can I tell isearch to ignore the contents of folded blocks by default in org-mode buffers?

More specifically, I'd like isearch to ignore contents of comment blocks and drawers: When authoring documents in org-mode I often use comment blocks and custom drawers to store different kinds of notes about the text I am writing. I keep them folded by default to make sure their contents don't distract me:

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

This works really well, but won't stop org-mode from expanding these blocks if they contain matches for a string I am isearching.

2 Answers 2


You can set search-invisible to nil in your .emacs or using Customize. Then, if you do want to show matches in invisible text, press M-s i while using isearch.

(I found this by reading the docs of isearch-forward and isearch-toggle-invisible, but it is also documented in the manual: see Special Isearch.)

This affects all buffers, not just Org; if you want to use nil in org-mode buffers and the default elsewhere you can create a buffer-local binding in Org buffers:

(add-hook 'org-mode-hook
          (lambda ()
            (make-local-variable 'search-invisible)
            (setq search-invisible nil)))
  • 1
    A buffer-local value would be way more practical than a let binding advice. :-)
    – Malabarba
    Commented Nov 28, 2014 at 0:28
  • @Malabarba: Very true! (I didn't know that one can use make-local-variable to create a buffer-local binding for a variable that is already defined as global -- until now, that is. I'm still learning stuff. :-) ) I'll update the answer. Commented Nov 28, 2014 at 4:17
  • Why not use setq-local instead of make-local-variable and setq? Commented Feb 22, 2022 at 7:09
  • We could use setq-local here of course --and probably should when Emacses before 24.2 don't need to be supported-- because it is identical to make-local-variable with setq. The answer was written before wide adoptability of setq-local, that's all.
    – Y. E.
    Commented Apr 1, 2023 at 14:26

While using isearch you can toggle the search on invisible text with M-s i.

You can also customize this behaviour with M-x customize-group isearch and searching for Search Invisible.

Note that this will ignore everything in a folded block, I can't ignore only the text in a commented block.

  • The two of us must have been typing at the same time! :-) Commented Nov 27, 2014 at 16:47

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.