When searching using Spotlight for, say, the word "Exotic", it fails to report the file Important_Exotic_Class.h, containing a C++ class by that name.

Can you think of a method to make Spotlight index the portions of identifiers between underscores in .h and .cpp files? In the example above, the three words would be indexed.

Even just indexing the words between underscores in filenames would be very useful.

  • It looks like Spotlight should be treating the underscore as a word separator. If you rename the file to "Important Exotic Class.h" (replacing the underscores with spaces), or create a new text file with that name, will Spotlight then include that file when you search for "Exotic"?
    – joelseph
    Oct 3, 2011 at 7:18

1 Answer 1


Spotlight should already index these files, it does on my Mac. Try searching for them as follows:

  • Open a Finder window
  • Press Command+F
  • Change the search parameters to "Name" and "contains" to search for file names or just "Contents" to search text within the files
  • Enter your search term

Once you start typing, spotlight should start showing results in the window

Note: Check in the 'Privacy' tab of the Spotlight preference pane in System Preferences to ensure you haven't excluded the folder/drive where your .h and .cpp files reside.

  • "Name" and "contains" do indeed reveal between-the-underscores words. One can even restrict the search to a given pair (word1_word2).
    – Calaf
    Oct 4, 2011 at 3:32
  • You can also use filename as opposed to name to avoid items like emails that have names containing your search term. It's good to understand the difference between Spotlight's matches and contains as well. Oct 17, 2022 at 13:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .