A fast open source text search tool, optimized for software development
The Silver Searcher is a fast open-source text search tool designed to quickly find patterns in files, optimized for use in software development environments. Offering real-time indexing, support for regular expressions, and integration with common file systems, it provides efficient code searching capabilities.
Key Features:
Real-time indexing for instant results
Ability to handle large codebases with high performance
Smart ignore patterns (e.g., .gitignore) to skip unnecessary files
Cross-platform compatibility
Support for regular expressions and advanced search options
Ideal for developers, DevOps engineers, and software teams working on large-scale projects, The Silver Searcher helps accelerate workflows by reducing the time spent searching through codebases. It can be installed via winget for easy setup.
It is dedicated to building a well behaved version of ag.exe for Windows.
The original version can be built for Windows using MinGW, but it has several serious shortcomings that limit its usefulness for Windows users world-wide.
This version has the following improvements:
Use and display Windows paths with the \ character.
Expand pathnames with wildcards. (As, contrary to Unix shells, cmd.exe and PowerShell don't expand them.)
The -? option displays help.
The -V/--version option displays details about this port, and every library used.
Support command line arguments with non-ASCII characters in any console code page.
Correctly display pathnames and matching strings with non-ASCII characters in any console code page, even if they're not part of the code page.
Use PCRE UTF8 option, allowing to search for non-ASCII regular expressions. (Like "." matching 1 character = 1 to 4 bytes!)
Support Unicode escape sequences \uXXXX and \UXXXXXXXX in the search pattern.
Support the three text files encodings standard in each version of Windows, the system code page, UTF-8, and UTF-16, and display matches correctly for all.
(Dynamically detects each file encoding.) (The system code page is Windows-localization-specific. Ex: Code page 1252 for the USA version.)
Note that searching in UTF-16 files has a performance cost, as the text is converted to UTF-8 first. This is not the case for the other supported encodings.
Also support UTF-8 and the current console code page encodings for text piped through the standard input.
(The console code page being often different from the system code page. Ex: Code page 437 by default for the USA version.)
Support pathnames longer than 260 characters, up to 64 KB on NTFS volumes, even on old versions of Windows like XP and 7.
Support Windows junctions and symbolic links.
Support 64-bit statistics even for the 32-bit build. (Allows searching through more than 4GB of files with the x86 build.)
The debug version displays the thread number ahead of each debug message.
Can be built with Microsoft Visual Studio versions 2013 to 2019, without any dependency on outside libraries.
Last but not least, everything (ag.exe with all its provided dependent libraries) is built with a single make.bat command.
Versions of Windows supported:
The 32-bits version runs in Windows XP, and all later versions of Windows.
The 64-bits version runs in all AMD64 versions of Windows.
It ignores file patterns from your .gitignore and .hgignore.
If there are files in your source repo you don't want to search, just add their patterns to a .ignore file. (*cough* *.min.js *cough*)
The command name is 33% shorter than ack, and all keys are on the home row!
Ag is quite stable now. Most changes are new features, minor bug fixes, or performance improvements. It's much faster than Ack in my benchmarks:
ack test_blah ~/code/ 104.66s user 4.82s system 99% cpu 1:50.03 total
ag test_blah ~/code/ 4.67s user 4.58s system 286% cpu 3.227 total
Ack and Ag found the same results, but Ag was 34x faster (3.2 seconds vs 110 seconds). My ~/code directory is about 8GB. Thanks to git/hg/ignore, Ag only searched 700MB of that.
Another version with additional features optimized for Windows is available there.
Supports text files encoded in both Windows System code page (Ex: CP 1252) and UTF-8.
Supports unicode search strings, and outputs Unicode results.
Supports unicode pathname > 260 characters, junctions, and symbolic links.
winget
winget install "The Silver Searcher"
Notes:
This installs a release of ag.exe optimized for Windows.
winget.exe now is the default command-line package manager for Windows 10 and Windows 11.
It is supported on Windows 10 build 1709 or newer.
If needed, it can be installed from the Microsoft Store, where it is called "App Installer".
It can also be installed manually using instructions on its github home.
The setup script in the Ag's winget package installs ag.exe in the first directory that matches one of these criteria:
Over a previous instance of ag.exe from the same origin found in the PATH
In the directory defined in environment variable bindir_%PROCESSOR_ARCHITECTURE%
In the directory defined in environment variable bindir
In the directory defined in environment variable windir
The setup script detects other ag.exe installations done by Chocolatey or Scoop, and aborts if one is found.
Any installation done with another package manager should be removed before installing a new one with winget. Ex: choco uninstall ag or scoop uninstall ag
Building release tarballs requires the same dependencies, except for automake and pkg-config. Once you've installed the dependencies, just run:
./configure
make
make install
You may need to use sudo or run as root for the make install.
Editor Integration
Vim
You can use Ag with ack.vim by adding the following line to your .vimrc:
let g:ackprg = 'ag --nogroup --nocolor --column'
or:
let g:ackprg = 'ag --vimgrep'
Which has the same effect but will report every match on the line.
Emacs
You can use ag.el as an Emacs front-end to Ag. See also: helm-ag.
TextMate
TextMate users can use Ag with my fork of the popular AckMate plugin, which lets you use both Ack and Ag for searching. If you already have AckMate you just want to replace Ack with Ag, move or delete "~/Library/Application Support/TextMate/PlugIns/AckMate.tmplugin/Contents/Resources/ackmate_ack" and run ln -s /usr/local/bin/ag "~/Library/Application Support/TextMate/PlugIns/AckMate.tmplugin/Contents/Resources/ackmate_ack"
Other stuff you might like
Ack - Better than grep. Without Ack, Ag would not exist.