Skip to content
Weston Ganger edited this page May 31, 2019 · 23 revisions

Advanced Usage

Ignoring files

By default, Ag will read the patterns in .gitignore and .hgignore files in directories it searches. If your source control doesn't care about a file, why should your source-searching program?

  • Patterns with Single asterisks * must be prefixed with a leading /. Example:
    • Bad: my-folder/*/vendor/*
    • Good: /my-folder/*/vendor/*
  • Currently double asterisks ** patterns in .gitignore and .hgignore are not recognized.

.ignore

You can also create .ignore files to ignore things that are in your source repository. .ignore uses the same patterns as .gitignore and .hgignore. Using .ignore can drastically improve search speeds. A common speedup is to ignore extern. If you want a global .ignore file, consider adding this alias: alias ag='ag --path-to-ignore ~/.ignore' to your ~/.bash_profile (or similar) file.

.agignore

The .agignore file was removed in favor of .ignore as part of the 2.0.0 release.

Ignoring from the command line

The -G option lets you specify a regex of file names to search. Any file name not matching this pattern will be ignored. For example, ag -G manager class will find instances of the string "class" in all files with the string "manager" in their name.

Clone this wiki locally