2012-08-16 23:41:25 -04:00
|
|
|
*ack.txt* Plugin that integrates ack with Vim
|
|
|
|
|
|
|
|
==============================================================================
|
|
|
|
Author: Antoine Imbert <antoine.imbert+ackvim@gmail.com> *ack-author*
|
|
|
|
License: Same terms as Vim itself (see |license|)
|
|
|
|
|
2016-06-26 14:30:37 -04:00
|
|
|
This plugin is only available if 'compatible' is not set.
|
|
|
|
|
|
|
|
{Vi does not have any of this}
|
|
|
|
|
2012-08-16 23:41:25 -04:00
|
|
|
==============================================================================
|
|
|
|
INTRODUCTION *ack*
|
|
|
|
|
|
|
|
This plugin is a front for the Perl module App::Ack. Ack can be used as a
|
|
|
|
replacement for grep. This plugin will allow you to run ack from vim, and
|
|
|
|
shows the results in a split window.
|
|
|
|
|
|
|
|
:Ack[!] [options] {pattern} [{directory}] *:Ack*
|
|
|
|
|
|
|
|
Search recursively in {directory} (which defaults to the current
|
|
|
|
directory) for the {pattern}. Behaves just like the |:grep| command, but
|
|
|
|
will open the |Quickfix| window for you. If [!] is not given the first
|
2016-06-26 14:30:37 -04:00
|
|
|
occurrence is jumped to.
|
2012-08-16 23:41:25 -04:00
|
|
|
|
|
|
|
:AckAdd [options] {pattern} [{directory}] *:AckAdd*
|
|
|
|
|
|
|
|
Just like |:Ack|, but instead of making a new list, the matches are
|
|
|
|
appended to the current |quickfix| list.
|
|
|
|
|
|
|
|
:AckFromSearch [{directory}] *:AckFromSearch*
|
|
|
|
|
|
|
|
Just like |:Ack| but the pattern is from previous search.
|
|
|
|
|
|
|
|
:LAck [options] {pattern} [{directory}] *:LAck*
|
|
|
|
|
|
|
|
Just like |:Ack| but instead of the |quickfix| list, matches are placed in
|
|
|
|
the current |location-list|.
|
|
|
|
|
|
|
|
:LAckAdd [options] {pattern} [{directory}] *:LAckAdd*
|
|
|
|
|
|
|
|
Just like |:AckAdd| but instead of the |quickfix| list, matches are added
|
|
|
|
to the current |location-list|
|
|
|
|
|
|
|
|
:AckFile [options] {pattern} [{directory}] *:AckFile*
|
|
|
|
|
|
|
|
Search recursively in {directory} (which defaults to the current
|
|
|
|
directory) for filenames matching the {pattern}. Behaves just like the
|
|
|
|
|:grep| command, but will open the |Quickfix| window for you.
|
|
|
|
|
2013-04-13 13:45:21 -04:00
|
|
|
:AckHelp[!] [options] {pattern} *:AckHelp*
|
|
|
|
|
2014-04-18 08:58:02 -04:00
|
|
|
Search vim documentation files for the {pattern}. Behaves just like the
|
2013-04-13 13:45:21 -04:00
|
|
|
|:Ack| command, but searches only vim documentation .txt files
|
|
|
|
|
|
|
|
:LAckHelp [options] {pattern} *:LAckHelp*
|
|
|
|
|
|
|
|
Just like |:AckHelp| but instead of the |quickfix| list, matches are placed
|
|
|
|
in the current |location-list|.
|
|
|
|
|
2014-04-18 08:58:02 -04:00
|
|
|
:AckWindow[!] [options] {pattern} *:AckWindow*
|
|
|
|
|
|
|
|
Search all buffers visible in the screen (current tab page only) files for
|
|
|
|
the {pattern}.
|
|
|
|
|
|
|
|
:LAckWindow [options] {pattern} *:LAckWindow*
|
|
|
|
|
|
|
|
Just like |:AckWindow| but instead of the |quickfix| list, matches are
|
|
|
|
placed in the current |location-list|.
|
|
|
|
|
2012-08-16 23:41:25 -04:00
|
|
|
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
|
|
|
|
line.
|
|
|
|
|
2015-02-24 05:45:22 -05:00
|
|
|
Note that if you are using Dispatch.vim with |g:ack_use_dispatch|, location
|
|
|
|
lists are not supported, because Dispatch does not support them at this time.
|
|
|
|
`:LAck` versions of commands above will give a warning and proceed to use the
|
|
|
|
quickfix list instead.
|
|
|
|
|
|
|
|
See http://beyondgrep.com/ for more information on searching with ack.
|
2012-08-16 23:41:25 -04:00
|
|
|
|
2014-04-18 08:58:02 -04:00
|
|
|
|
|
|
|
==============================================================================
|
|
|
|
CONFIGURATION *ack-configuration*
|
|
|
|
|
|
|
|
*g:ackprg*
|
|
|
|
g:ackprg
|
|
|
|
Default for ubuntu: "ack-grep"
|
|
|
|
Default for other systems: "ack"
|
|
|
|
|
2015-07-13 06:22:46 -04:00
|
|
|
Use this option to specify the search command and its default arguments.
|
2014-04-18 08:58:02 -04:00
|
|
|
|
|
|
|
Example:
|
|
|
|
>
|
2015-07-13 06:22:46 -04:00
|
|
|
let g:ackprg = "ag --vimgrep"
|
2014-04-18 08:58:02 -04:00
|
|
|
<
|
2014-07-02 07:18:18 -04:00
|
|
|
*g:ack_default_options*
|
2014-04-18 08:58:02 -04:00
|
|
|
g:ack_default_options
|
|
|
|
Default: " -s -H --nocolor --nogroup --column"
|
|
|
|
|
2015-07-13 06:22:46 -04:00
|
|
|
Use this option to specify the default arguments given to `ack`. This is only
|
|
|
|
used if |g:ackprg| has not been customized from the default--if you are using
|
|
|
|
a custom search program instead of Ack, set your preferred options in
|
|
|
|
|g:ackprg|.
|
|
|
|
|
|
|
|
NOTE: This option may be deprecated in the future. ~
|
2014-04-18 08:58:02 -04:00
|
|
|
|
|
|
|
Example:
|
|
|
|
>
|
2014-07-02 07:18:18 -04:00
|
|
|
let g:ack_default_options =
|
2014-04-18 08:58:02 -04:00
|
|
|
\ " -s -H --nocolor --nogroup --column --smart-case --follow"
|
|
|
|
<
|
|
|
|
*g:ack_apply_qmappings*
|
|
|
|
g:ack_apply_qmappings
|
|
|
|
Default: 1
|
|
|
|
|
2016-06-26 14:30:37 -04:00
|
|
|
This option enables mappings on the |quickfix| window.
|
2014-04-18 08:58:02 -04:00
|
|
|
|
|
|
|
*g:ack_apply_lmappings*
|
|
|
|
g:ack_apply_lmappings
|
|
|
|
Default: 1
|
|
|
|
|
2016-06-26 14:30:37 -04:00
|
|
|
This option enables mappings on |location-list| windows.
|
2014-04-18 08:58:02 -04:00
|
|
|
|
|
|
|
*g:ack_mappings*
|
|
|
|
g:ack_mappings
|
|
|
|
Default: {
|
|
|
|
\ "t": "<C-W><CR><C-W>T",
|
|
|
|
\ "T": "<C-W><CR><C-W>TgT<C-W>j",
|
|
|
|
\ "o": "<CR>",
|
|
|
|
\ "O": "<CR><C-W><C-W>:ccl<CR>",
|
|
|
|
\ "go": "<CR><C-W>j",
|
|
|
|
\ "h": "<C-W><CR><C-W>K",
|
|
|
|
\ "H": "<C-W><CR><C-W>K<C-W>b",
|
|
|
|
\ "v": "<C-W><CR><C-W>H<C-W>b<C-W>J<C-W>t",
|
|
|
|
\ "gv": "<C-W><CR><C-W>H<C-W>b<C-W>J" }
|
|
|
|
|
|
|
|
This option list all maps create on quickfix/Location list window.
|
|
|
|
|
|
|
|
Example, if you want to open the result in the middle of the screen:
|
|
|
|
>
|
|
|
|
let g:ack_mappings = { "o": "<CR>zz" }
|
|
|
|
<
|
|
|
|
*g:ack_qhandler*
|
|
|
|
g:ack_qhandler
|
|
|
|
Default: "botright copen"
|
|
|
|
|
|
|
|
Command to open the quickview window.
|
|
|
|
|
|
|
|
If you want to open a quickview window with 30 lines you can do:
|
|
|
|
>
|
|
|
|
let g:ack_qhandler = "botright copen 30"
|
|
|
|
<
|
|
|
|
*g:ack_lhandler*
|
|
|
|
g:ack_lhandler
|
|
|
|
Default: "botright lopen"
|
|
|
|
|
|
|
|
Command to open the Location list window.
|
|
|
|
|
|
|
|
If you want to open a Location list window with 30 lines you can do:
|
|
|
|
>
|
|
|
|
let g:ack_lhandler = "botright lopen 30"
|
|
|
|
<
|
|
|
|
*g:ackhighlight*
|
|
|
|
g:ackhighlight
|
|
|
|
Default: 0
|
|
|
|
|
|
|
|
Use this option to highlight the searched term.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
>
|
|
|
|
let g:ackhighlight = 1
|
|
|
|
<
|
|
|
|
*g:ack_autoclose*
|
|
|
|
g:ack_autoclose
|
|
|
|
Default: 0
|
|
|
|
|
|
|
|
Use this option to specify whether to close the quickfix window after
|
|
|
|
using any of the shortcuts.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
>
|
|
|
|
let g:ack_autoclose = 1
|
|
|
|
<
|
|
|
|
*g:ack_autofold_results*
|
|
|
|
g:ack_autofold_results
|
|
|
|
Default: 0
|
|
|
|
|
|
|
|
Use this option to fold the results in quickfix by file name. Only the current
|
|
|
|
fold will be open by default and while you press 'j' and 'k' to move between the
|
|
|
|
results if you hit other fold the last one will be closed and the current will
|
|
|
|
be open.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
>
|
|
|
|
let g:ack_autofold_results = 1
|
|
|
|
<
|
|
|
|
*g:ackpreview*
|
|
|
|
g:ackpreview
|
|
|
|
Default: 0
|
|
|
|
|
|
|
|
Use this option to automagically open the file with 'j' or 'k'.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
>
|
|
|
|
let g:ackpreview = 1
|
|
|
|
<
|
2014-07-02 07:18:18 -04:00
|
|
|
*g:ack_use_dispatch*
|
|
|
|
g:ack_use_dispatch
|
|
|
|
Default: 0
|
|
|
|
|
2015-02-24 05:45:22 -05:00
|
|
|
Use this option to use vim-dispatch to run searches in the background, with a
|
|
|
|
variety of execution backends for different systems.
|
|
|
|
|
|
|
|
Due to limitations in Dispatch at this time, location lists are unsupported
|
|
|
|
and result windows will appear before results are ready. Still, these may be
|
|
|
|
acceptable tradeoffs for very large projects where searches are slow.
|
2014-07-02 07:18:18 -04:00
|
|
|
|
|
|
|
Example:
|
|
|
|
>
|
|
|
|
let g:ack_use_dispatch = 1
|
|
|
|
<
|
2016-05-14 07:57:54 -04:00
|
|
|
*g:ack_use_cword_for_empty_search*
|
|
|
|
g:ack_use_cword_for_empty_search
|
|
|
|
Default: 1
|
|
|
|
|
|
|
|
Use this option to enable blank searches to run against the word under the
|
|
|
|
cursor. When this option is not set, blank searches will only output an error
|
|
|
|
message.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
>
|
|
|
|
let g:ack_use_cword_for_empty_search = 0
|
|
|
|
<
|
2012-08-16 23:41:25 -04:00
|
|
|
==============================================================================
|
|
|
|
MAPPINGS *ack-mappings*
|
|
|
|
|
2016-06-26 14:30:37 -04:00
|
|
|
The following keyboard shortcuts are available in the |quickfix| and
|
|
|
|
|location-list| windows:
|
2012-08-16 23:41:25 -04:00
|
|
|
|
2016-06-26 14:30:37 -04:00
|
|
|
? display a quick summary of these mappings.
|
2012-08-16 23:41:25 -04:00
|
|
|
|
2016-06-26 14:30:37 -04:00
|
|
|
o open file (same as Enter).
|
|
|
|
|
|
|
|
O open file and close the quickfix window.
|
2014-04-18 08:58:02 -04:00
|
|
|
|
2012-08-16 23:41:25 -04:00
|
|
|
go preview file (open but maintain focus on ack.vim results).
|
|
|
|
|
|
|
|
t open in a new tab.
|
|
|
|
|
2016-06-26 14:30:37 -04:00
|
|
|
T open in new tab without moving to it.
|
2012-08-16 23:41:25 -04:00
|
|
|
|
2013-04-13 13:45:21 -04:00
|
|
|
h open in horizontal split.
|
|
|
|
|
2016-06-26 14:30:37 -04:00
|
|
|
H open in horizontal split, keeping focus on the results.
|
2013-04-13 13:45:21 -04:00
|
|
|
|
2012-08-16 23:41:25 -04:00
|
|
|
v open in vertical split.
|
|
|
|
|
2016-06-26 14:30:37 -04:00
|
|
|
gv open in vertical split, keeping focus on the results.
|
2012-08-16 23:41:25 -04:00
|
|
|
|
|
|
|
q close the quickfix window.
|
2016-06-26 14:30:37 -04:00
|
|
|
|
|
|
|
To adjust these, see |g:ack_mappings|.
|
|
|
|
|
|
|
|
==============================================================================
|
|
|
|
Ignoring files *ack-ignore*
|
|
|
|
|
|
|
|
If you're using this plugin with ag, The Silver Searcher, bear in mind that:
|
|
|
|
|
|
|
|
- It ignores file patterns from your .gitignore and .hgignore.
|
|
|
|
|
|
|
|
- If there are other files in your source repository you don't wish to
|
|
|
|
search, you can add their patterns to an .agignore file.
|
|
|
|
|
|
|
|
==============================================================================
|
|
|
|
ISSUES AND FAQ *ack-issues-and-faq*
|
|
|
|
|
|
|
|
I use NERDTree and opening ack.vim results in a vertical split displaces it.~
|
|
|
|
|
|
|
|
You are probably using NERDTree with its default alignment at the left
|
|
|
|
side of the window. Set these custom mappings in your vimrc to work around
|
|
|
|
this:
|
|
|
|
>
|
|
|
|
let g:ack_mappings = {
|
|
|
|
\ 'v': '<C-W><CR><C-W>L<C-W>p<C-W>J<C-W>p',
|
|
|
|
\ 'gv': '<C-W><CR><C-W>L<C-W>p<C-W>J' }
|
|
|
|
<
|
|
|
|
This solution will be improved in the future.
|
|
|
|
|
|
|
|
Results show a mix of relative and absolute paths, making them hard to read.~
|
|
|
|
|
|
|
|
This is a quirk of Vim that can happen with plain |:vimgrep| too. You can
|
|
|
|
try this in your vimrc to work around it:
|
|
|
|
>
|
|
|
|
autocmd BufAdd * exe "cd" fnameescape(getcwd())
|
|
|
|
<
|
|
|
|
but for some users this may be disruptive to their Vim workflow. For more
|
|
|
|
details, see:
|
|
|
|
|
|
|
|
http://vi.stackexchange.com/a/4816/7174
|
|
|
|
https://github.com/mileszs/ack.vim/issues/143
|
|
|
|
|
|
|
|
vim:set et sw=4 ts=4 tw=78:
|