Adding number of instances of a word or phrase found in a note to "Find in file"

Use case or problem

I’m trying to find the number of times I wrote a specific word or phrase in a single note.

Proposed solution

I think this feature could easily be implemented in the current “search file” (CTRL + F) or “search & replace” (CTRL + H) function for finding instances of a word or phrase in a note. It would just need to also count how many instances it finds and display it on-screen.

Current workaround

The ways I currently see to do this are:

  • Using the current “search file” menu via CTRL + F and going from instance to instance manually, counting until I reach the bottom of the note.
  • Copy-pasting the note into Microsoft Word or another program and finding the number of counts from there.
  • Creating a program in python or another programming language that auto-counts (I’m not very experienced in programming myself though so I have not tried this yet)
36 Likes

Hello,
I am looking for something like this. I want to know how many times I used a word in a document. Have you found a solution to this?

1 Like

Hi, unfortunately I have not found a solution to this yet. The closest thing I have found is the Better Word Count plugin, but that only returns the number of words and characters in a single highlight, not number of specific words or phrases in a document. Otherwise I’ve been primarily using the workaround of copy-pasting into Microsoft Word or exporting to PDF whenever I’ve needed to find number of instances.

3 Likes

I would like to echo a request for this feature. As a writer (not wanting to repeat the same word too often) it would be handy to search a note and see how many occurrences of that word are present.

1 Like

+1; Should(?) be a really easy addition to the “find” function, as well as possibly the global search, is to simply display the number of results.

Use case or problem

When using the search function, I would like a feature to count of the number of records found in a search. This would be a great help when comparing two or more searches to see if the count is different.

Proposed solution

This could be acheived in a simular way to the way the community plugin “file explorer folder count” works.

2 Likes

I will also add that there should be the current position displayed, such as x/y or x of y, when seeking (next, prev) through matches in the find search.

I found a workaround! And I’d also like to add a big +1 because this feature - showing “Result x of y” when using CTRL + F within a note would be so much more user friendly.

Workaround: use the vault-wide search to search for the filename, then the search term.

  1. Expand sidebar
  2. Click the magnifying glass
  3. In the vault-wide search, enter file:name_of_note "search term"

That view will show you the number of times your search term was found within the note. If your search term is rare, you can even omit the filename.

I understand that keeping conversations in single threads helps the community, but am I allowed to link to a similar thread that was opened around the same time? The reason being that while it is less well explained and has fewer replies, it has 24 likes.

4 Likes

Find count (x of y) is an absolutely essential feature of Obsidian that is missing. For a reference on how this feature should work, please refer to the in-editor Find and Replace feature of Visual Studio Code.

5 Likes

Basically, I wish Obsidian has these:

Use case or problem

For example, when I search for a word “cat” within an obsidian page (ctrl+f), I can only go through the search result one by one. I do not know how many "cat"s there are in this document, which one I’m at, or have I been to the same result more than once already.

Proposed solution

Like in the screen shot, when using in-document search, show a count of how many results there are in this page and which one I am currently at.

Secondary features that would also be nice:

  1. Also highlight results that I’m currently not at.( in preview mode)
  2. Mark the scroll bar where the results are.

Related feature requests (optional)

3 Likes

+1, currently the most missing features imo. as others pointed out, i’d love to see these features as soon as possible in obsidian:

  • show occurences of the currently searched phrase
  • highlight all the currently searched occurences in your text (like the orange highlight browser does), whether in reader, source or live preview modes.

thanks a lot to obsidian devs!

Definitely a +1 for this, I’ve been using Obsidian as my writing program of choice because it’s easy to organize, however not having something like this makes it a tad difficult to analyze my document for reoccurring phrases and the density of specific words or phrases throughout the document.

As a complete and utter Python beginner I needed a quick solution to this problem so I mocked up a small program which accepts absolute path to an .md file and then returns a list outlining all repeated words (n>=2) with info on how many times they’ve been mentioned.

There are a couple of caveats; I’m writting short form content so the program is designed to check the text located under a generic # Heading. Your .md file should look like this in order for my solution to be applicable:

Heading

Prius et infelix? Alter bene flerunt quoque illa, Dianae possent replent
aequalis sed interea, et simul exit forma. Voverat quorum miserabile, defendere
absens tibi manat Hyacinthon vobis. Sedes quod est et in perituraque videbam nec
terrae, deos passaque velle simulacra similes!

Lorem markdownum aptas et diversis, refugis ipse quoque, ergo. Ore et amat,
fatemur ego Caeneus sed servatusque, inpia increpuit eris. Inque convertor
turbatum fuso. Date adiit aera criminis, inmoriuntur tenens dabitur, ales?

Etc.

You can either run it by using your own Python interpreter after downloading the function module (f_md_repeats.my) with the script itself (md_script.py) or you can download the executable that will almost surely be recognized as a Trojan due to Python really not really being suited to .exe packaging.

1 Like

Actually I’m quite shocked there is still no indication of results found in the status bar of Obsidian.

How does it apply to my case? There are notes exported from Dynalist and converted to tables: films watched, books read, etc. Previously I was able to easily filter out (get number of), say, things I liked by means of searching for “liked” keyword. Now I have either to copy/paste the contents to some third-party editor with required search verbosity like Sublime Text or to use some third-party terminal or GUI search application like RipGrep, DnGrep, Astrogrep. So counter-intuitive!

Come on, Obsidian, wtf?!

2 Likes

I’m adding a very big +1 for this, as it’s a feature I use often in text apps, word processors, and code editors. As a writing instructor, I’ve often suggested this feature in other programs to my students as part of their editing process—and many say that seeing the total has helped them to better perceive how their writing is repetitious.

Is the reason this hasn’t happened yet because of something specific to CodeMirror, difficulty deciding how to display the total results, or something else?

If it’s a question of how to display the total, another approach I’ve seen in notes apps is to display the “x of y total” within the search field. Or those numbers could be displayed only in the already-larger “Find and Replace” and omitted in the streamlined “Find” feature.

1 Like

Very big +1

+1, this would be very useful!

The easier way would be to add a temporary span in the status bar when there is a selection → 3 occurrences… maybe after 3 characters at least selected, if several occurrences are found, and an option to show only words occurrences. I will try to do it.

I did it you can see the result there. it’s on the plugin Duplicate Line
there

I upvote this.