Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions autoload/ag.vim
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ if !exists("g:ag_mapping_message")
let g:ag_mapping_message=1
endif

if !exists("g:ag_use_wildignore")
let g:ag_use_wildignore=1
endif

function! ag#Ag(cmd, args)
let l:ag_executable = get(split(g:agprg, " "), 0)

Expand All @@ -41,6 +45,11 @@ function! ag#Ag(cmd, args)
let l:grepargs = a:args . join(a:000, ' ')
end

" Possibly add --ignore flags for patterns set in the 'wildignore' option
if g:ag_use_wildignore
let g:agprg = ag#AddWildignoreToAgCommand(g:agprg)
endif

" Format, used to manage column jump
if a:cmd =~# '-g$'
let s:agformat_backup=g:agformat
Expand Down Expand Up @@ -123,6 +132,16 @@ function! ag#Ag(cmd, args)
endif
endfunction

function! ag#AddWildignoreToAgCommand(cli_arguments)
let l:new_arguments = copy(a:cli_arguments)

for ignore_me in split(&wildignore, ",")
let l:new_arguments = printf("%s --ignore \"%s\"", l:new_arguments, l:ignore_me)
endfor

return l:new_arguments
endfunction

function! ag#AgFromSearch(cmd, args)
let search = getreg('/')
" translate vim regular expression to perl regular expression.
Expand Down
47 changes: 26 additions & 21 deletions doc/ag.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
==============================================================================
INTRODUCTION *ag*

This plugin is a front for the_silver_searcher: ag. Ag can be used as a
replacement for ack. This plugin will allow you to run ag from vim, and
shows the results in a split window.
This plugin is a front for the_silver_searcher: ag. Ag can be used as a
replacement for ack. This plugin will allow you to run ag from vim, and shows
the results in a split window.

:Ag[!] [options] {pattern} [{directory}] *:Ag*

Search recursively in {directory} (which defaults to the current
directory) for the {pattern}. Behaves just like the |:grep| command, but
directory) for the {pattern}. Behaves just like the |:grep| command, but
will open the |Quickfix| window for you. If [!] is not given the first
error is jumped to.

Expand All @@ -36,12 +36,12 @@ shows the results in a split window.
:AgFile [options] {pattern} [{directory}] *:AgFile*

Search recursively in {directory} (which defaults to the current
directory) for filenames matching the {pattern}. Behaves just like the
directory) for filenames matching the {pattern}. Behaves just like the
|:grep| command, but will open the |Quickfix| window for you.

:AgHelp[!] [options] {pattern} *:AgHelp*

Search vim documentation files for the {pattern}. Behaves just like the
Search vim documentation files for the {pattern}. Behaves just like the
|:Ag| command, but searches only vim documentation .txt files

:LAgHelp [options] {pattern} *:LAgHelp*
Expand All @@ -50,8 +50,8 @@ shows the results in a split window.
in the current |location-list|.

Files containing the search term will be listed in the split window, along
with the line number of the occurrence, once for each occurrence. <Enter> on
a line in this window will open the file, and place the cursor on the matching
with the line number of the occurrence, once for each occurrence. <Enter> on a
line in this window will open the file, and place the cursor on the matching
line.

See http://geoff.greer.fm/2011/12/27/the-silver-searcher-better-than-ack/ for
Expand All @@ -62,18 +62,18 @@ OPTIONS *ag-options*

*g:agprg*
The location of the Ag program, and any options you want passed to it before
searching. Default: "ag --column". Example: >
searching. Default: "ag --column". Example: >
let g:agprg="ag --column --smart-case"
<

*g:aghighlight*
If 1, highlight the search terms after searching. Default: 0. Example: >
If 1, highlight the search terms after searching. Default: 0. Example: >
let g:aghighlight=1
<

*g:agformat*
Format to recognize the matches. See 'errorformat' for more info. Default:
"%f" when searching for files, "%f:%l:%c:%m" if not otherwise set. For
Format to recognize the matches. See 'errorformat' for more info. Default:
"%f" when searching for files, "%f:%l:%c:%m" if not otherwise set. For
example, if your `g:agprg` is set to just "ag" (no column numbers in the
output, so when you jump to a match your cursor will be on the start of the
line): >
Expand All @@ -82,37 +82,42 @@ line): >

*g:ag_apply_lmappings*
Whether or not to add custom mappings to location list windows opened by this
plugin. Only applies if you're using the location list. Default 1. Example: >
plugin. Only applies if you're using the location list. Default 1. Example: >
let g:ag_apply_lmappings=0
<

*g:ag_apply_qmappings*
Whether or not to add custom mappings to quickfix windows opened by this
plugin. Only applies if you're using the error list. Default 1. Example: >
plugin. Only applies if you're using the error list. Default 1. Example: >
let g:ag_apply_qmappings=0
<

*g:ag_lhandler*
A custom command used to open the location list after it's populated.
Default: "botright lopen". You might want to set this to change where the
location list is opened, or what size it is. Example: >
Default: "botright lopen". You might want to set this to change where the
location list is opened, or what size it is. Example: >
let g:ag_lhandler="topleft lopen"
<

*g:ag_qhandler*
A custom command used to open the error list after it's populated. Default:
"botright copen". You might want to set this to change where the quickfix
window is opened, or what size it is. Example: >
A custom command used to open the error list after it's populated. Default:
"botright copen". You might want to set this to change where the quickfix
window is opened, or what size it is. Example: >
let g:ag_qhandler="copen 20"
<

*g:ag_mapping_message*
Whether or not to show the message explaining the extra mappings that are
added to the results list this plugin populates. This message is not shown if
added to the results list this plugin populates. This message is not shown if
the mappings are not applied (see |g:ag_apply_qmappings| and
|g:ag_apply_lmappings| for more info. Default 1. Example: >
|g:ag_apply_lmappings| for more info. Default 1. Example: >
let g:ag_mapping_message=0
<
*g:ag_use_wildignore*
Whether or not to ignore patterns specified in the 'wildignore' option.
Default 1. Example: >
let g:ag_use_wildignore=0
<

==============================================================================
MAPPINGS *ag-mappings*
Expand Down