Some time ago I was working on my first larger python codebase, it was pushing some half a million lines of code and lacked documentation. I noticed that one of the other engineers was getting results back from his searches much faster than I was. While my searches would often take minutes to complete, his where returning in seconds. That sent me off on a search to understand why, and to find a better tool.
To cut the story short, I found that the main reason my searches were slow was that they were searching everything. Every library and dependency in the repository. I could get things faster by building up lengthy grep ignore lists, but that felt like a kludge. Then, almost by accident I discovered a little gem: git grep yes, git has a built in code search tool! It behaves mostly like the good old grep you (may) be used to, but this one knows what code to ignore because you have already told git that (in your .gitignore file for example), and it is multithreaded. It is also universally available.
However if your needs are more specialized, there is an entire mini-ecosystem of such tools:
- Ack! The original “better than grep” code search tool, written in perl, and portable across Windows, Mac, Linux etc.
- The Silver Searcher Started off as a clone of Ack! but with a focus on speed, it has since diverged somewhat but retains the speed. Written in C with Windows builds available.
- The Platinum Searcher Intended to one-up The Silver Searcher with better Unicode support. Written in Go, with binaries available for Windows.
- Sift Another take, also written in Go with support across all common OSes.
- RipGrep Interestingly this is written in Rust and included binaries for the various OSes. The author appears to be thorough and working hard to go beyond the existing projects.
- Awk For the true unix geeks, can be a surprisingly powerful (and fast) search tool.