Editor Integration
Vim: ag.vim
Install ag.vim to use ag as the search backend:
" With vim-plug:
Plug 'rking/ag.vim'
" Usage:
" :Ag "TODO" — search and open quickfix list
" :AgFile "config" — search filenames
Vim: Direct grep Integration
Set ag as vim's grep program:
if executable('ag')
set grepprg=ag\ --nogroup\ --nocolor\ --column
set grepformat=%f:%l:%c:%m
endif
" Now use :grep "pattern" — results populate the quickfix list
Emacs: helm-ag
helm-ag uses ag as backend for interactive searching:
;; In your .emacs or init.el
(require 'helm-ag)
(global-set-key (kbd "C-c a") 'helm-ag)
(global-set-key (kbd "C-c A") 'helm-ag-project-root)
Shell Function: Interactive Jump
Add to ~/.bashrc / ~/.zshrc:
# Search with ag, pick result interactively with fzf, open in vim
agv() {
local file line
read -r file line <<< "$(ag --noheading --column "$@" | \
fzf --delimiter=':' --nth=1,2,3 | \
awk -F: '{print $1, $2}')"
[[ -n "$file" ]] && ${EDITOR:-vim} +"$line" "$file"
}
# Usage: agv "TODO"