How do I grep for a string in the file I am currently viewing? Currently when I run the find command it greps through all of the files in my project. (Which is nice!)
How do I limit search to existing open file?
The only find operation that runs over multiple files is Find > Find in Files
, so if you don’t use that, what you find will be limited to the current file automatically. For example, Find > Find...
, Find > Quick Find
and so on. The associated keyboard shortcuts for those are displayed in the menu if you’re not familiar with them.
Presumably you want to use Find > Find in Files...
so that Sublime will show you all of the matches all at once though, like grep does.
You can control where Find in Files
looks through the Where:
field. When you don’t type anything in there, the default (faintly visible as gray text) is Open files and folders
, which means it searches everything in your project.
You can use the button to the right of that field (with the three dots on it) to add extra items to the list of places to search. One of those items is Add Current File
, which adds the text <current file>
to the Where:
field, telling Sublime to search inside of the current file.
The Where
field can contain more than one item, all separated by commas, so you want to make sure that <current file>
is the only text you see in there. Otherwise it will try to look in other places too, which will make you sad.