Option to exclude comments from search

Use case or problem

I have commented material in my templates to remind myself to fill notes out in a certain way.

At the moment those comments are included in search results. I think it would be useful to have the option to exclude such meta-stuff so results focus on actual note content.

Proposed solution

Add a filter to search ignores material enclosed in comment tags ( <!-- or %% etc.)

Current workaround (optional)

I don’t have a workaround for this at the moment.

Related feature requests (optional)

Can’t find any.

1 Like

As a workaround you could use the line:() or block:() search syntax:

line:(searchword -"%%" -"<!--")

or

block:(searchword -"%%" -"<!--")

+1 on this. Also, having this as a button to toggle in the search pane would be perfect. Here’s another use case with the Excalidraw plugin :

  • Context : In Excalidraw drawings, the drawings JSON instructions are stored in a commented out section of the note (%% %%). These sections are very long even for smaller drawings.
  • Issue : when doing searches in the search pane with the “Show more context” toggled on, if the results of the query includes text that is part of an Excalidraw drawing, Obsidian becomes very laggy and seems to have a hard time processing the search.
    • I personally would prefer to exclude by default the contents of these Excalidraw drawings from my searches instead of having to always add an operator to exclude them.

+1: I’ve also stumbled upon this one.

In some template notes I use comment blocks to remind myself of relevant tags (easier to delete the unneeded ones). These tags show up in searches and mess up the tag count in the tag pane.

If your biggest concern is regarding the tags coming up when using the tag: operator in searches and your tag count, a good work around would be to put these tags inside inline code (#like-so) or code blocks within your comment blocks. That way Obsidian won’t consider them as tags. But note that they will obviously come up in searches if you search them directly (not using the tag: operator.

1 Like