How can I Spotlight search exclusively in `.txt` files in `~/.` on my disk?
In terminal app using the command line, this is easy to do.
mdfind -onlyin ~ Ramanujan|grep txt
You could make a complex query and get rid of the pipe to grep, but the above should work very quickly. You could probably assemble a finder search as well with about 12 clicks if you couldn’t use the command line tools.
i don't know how to select which files Spotlight searches if it does search inside of files. A possible workaround is to use the free app Easyfind available from the app store. An image of the EasyFind window is shown below.
By clicking on the Settings button on the top left you can open the sidebar shown on the left. This is where you'll check which files to search the contents of. I've clecked the files containing txt, among other extensions, in the files name.