Skip to content

Instantly share code, notes, and snippets.

@robert-claypool
Last active January 14, 2016 20:44
Show Gist options
  • Save robert-claypool/2f57bdee3b59f6eaba78 to your computer and use it in GitHub Desktop.
Save robert-claypool/2f57bdee3b59f6eaba78 to your computer and use it in GitHub Desktop.
Notes on Ag for Vim

Notes on ag.vim

This plugin is a front for ag, A.K.A. the_silver_searcher, https://github.com/rking/ag.vim

Usage: ag [FILE-TYPE] [OPTIONS] PATTERN [PATH]

Ag searches from your current working directory if a PATH is not given.

  • Check your working directory in Vim with :pwd
  • Change your working directory with :cd [PATH]

Examples

(1) Find 0px in any file except CSS.

:Ag --ignore *.css 0px

(2) How many 0px matches were found in each file?

:Ag --count --ignore *.css 0px

(3) Now ignore CSS and LESS.

:Ag --ignore *.css --ignore *.less 0px

(4) Find /form/Form only in HTML files.

:Ag -G html /form/Form or Ag -G html \/form\/Form

  • escaping / is optional
  • -G is an alias for --file-search-regex; regex is allowed as the name implies

(5) Find lines ending in Miles (use regex)

:Ag Miles$

Options

Options are documented at https://github.com/ggreer/the_silver_searcher/blob/master/doc/ag.1.md

Keyboard Shortcuts

In the quickfix window, you can use:

e    to open file and close the quickfix window
o    to open (same as enter)
go   to preview file (open but maintain focus on ag.vim results)
t    to open in new tab
T    to open in new tab silently
h    to open in horizontal split
H    to open in horizontal split silently
v    to open in vertical split
gv   to open in vertical split silently
q    to close the quickfix window
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment