How to grep lines matching string in current file?


Is there a way to show all lines matching a string (or regex) in the currently viewed file?



Find in Project displays each matched line, and you can put the filename into the bottom field to restrict the search to that specific file.


Thanks! I didn’t realize it was that easy!


For a lot of things, it’s usually very easy to achieve a “good enough” result with the tools available. Find in Project isn’t exactly a grep analog because you can’t then do other things with the search results. But you just want to see them all, so it’s good enough. It’s when you need a more specific or complex solution that you need to dig into the API, and so far I haven’t found anything that I wanted but was unable to accomplish. For a grep | nano imitation, you would use editor.scan(), pass it a function that takes object.range.getRows() and appends the content of those rows to a string, then pops open a new tab with atom.workspace.buildTextEditor() and drops the results string in. That’s a pretty quick add.


I have a vim function named MyGrep() mapped to which sound very similar to the functionality you describe. After I’m more comfortable with Atom I definitely plan on doing some hacking!

Can you recommend a good resource for example code?



Unfortunately, no, not yet. A cookbook is one of the things Atom presently lacks.