1
0
Fork 0
mirror of synced 2024-11-05 00:48:57 -05:00
ultimate-vim/sources_non_forked/ack.vim/README.md

162 lines
5.5 KiB
Markdown
Raw Normal View History

2014-04-18 08:58:02 -04:00
# ack.vim
2012-08-16 23:41:25 -04:00
2015-02-24 05:45:22 -05:00
Run your favorite search tool from Vim, with an enhanced results list.
This plugin was designed as a Vim frontend for the Perl module [App::Ack]. Ack
can be used as a replacement for 99% of the uses of _grep_. The plugin allows
2015-07-13 06:22:46 -04:00
you to run ack from Vim, and shows the results in a split window.
2015-02-24 05:45:22 -05:00
But here's a little secret for the Vim-seasoned: it's just a light wrapper for
Vim's [grepprg] and the [quickfix] window for match results. This makes it easy
to integrate with your own Vim configuration and use existing knowledge of core
features. It also means the plugin is flexible to use with other search tools.
[App::Ack]: http://search.cpan.org/~petdance/ack/ack
[grepprg]: http://vimdoc.sourceforge.net/htmldoc/options.html#'grepprg'
[quickfix]: http://vimdoc.sourceforge.net/htmldoc/quickfix.html#quickfix
2012-08-16 23:41:25 -04:00
2014-04-18 08:58:02 -04:00
## Installation
2012-08-16 23:41:25 -04:00
### Ack
2015-02-24 05:45:22 -05:00
You will need ack (>= 2.0), of course. To install it follow the
[manual](http://beyondgrep.com/install/).
2014-04-18 08:58:02 -04:00
### The Plugin
2015-02-24 05:45:22 -05:00
It is recommended to use one of the popular plugin managers for Vim. There are
many and you probably already have a preferred one, but a few examples for your
copy-and-paste convenience:
2012-08-16 23:41:25 -04:00
2015-07-13 06:22:46 -04:00
#### Pathogen
$ git clone https://github.com/mileszs/ack.vim.git ~/.vim/bundle/ack.vim
2014-04-18 08:58:02 -04:00
#### Vundle
2012-08-16 23:41:25 -04:00
2015-07-13 06:22:46 -04:00
```vim
Plugin 'mileszs/ack.vim'
```
2012-08-16 23:41:25 -04:00
2014-04-18 08:58:02 -04:00
#### NeoBundle
2012-08-16 23:41:25 -04:00
2015-07-13 06:22:46 -04:00
```vim
NeoBundle 'mileszs/ack.vim'
```
2012-08-16 23:41:25 -04:00
2015-02-24 05:45:22 -05:00
#### Manual (not recommended)
[Download][releases] the plugin and extract it in `~/.vim/` (or
`%PROGRAMFILES%/Vim/vimfiles` on Windows).
[zipball]: https://github.com/mileszs/ack.vim/archive/master.zip
2014-04-18 08:58:02 -04:00
## Usage
2012-08-16 23:41:25 -04:00
2014-04-18 08:58:02 -04:00
:Ack [options] {pattern} [{directories}]
2012-08-16 23:41:25 -04:00
2015-02-24 05:45:22 -05:00
Search recursively in `{directories}` (which defaults to the current directory)
for the `{pattern}`.
Files containing the search term will be listed in the quickfix 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.
2012-08-16 23:41:25 -04:00
2015-02-24 05:45:22 -05:00
Just like where you use `:grep`, `:grepadd`, `:lgrep`, and :`lgrepadd`, you can
use `:Ack`, `:AckAdd`, `:LAck`, and `:LAckAdd` respectively. (See `:help Ack`
after installing, or [`doc/ack.txt`][doc] in the repo, for more information.)
2012-08-16 23:41:25 -04:00
2015-02-24 05:45:22 -05:00
For more ack help see [ack documentation](http://beyondgrep.com/documentation/).
2012-08-16 23:41:25 -04:00
2015-02-24 05:45:22 -05:00
[doc]: https://github.com/mileszs/ack.vim/blob/master/doc/ack.txt
2012-08-16 23:41:25 -04:00
2014-04-18 08:58:02 -04:00
### Keyboard Shortcuts
2012-08-16 23:41:25 -04:00
2015-02-24 05:45:22 -05:00
The quickfix results window is augmented with these convenience mappings:
2012-08-16 23:41:25 -04:00
2015-02-24 05:45:22 -05:00
? a quick summary of these keys, repeat to close
o to open (same as Enter)
O to open and close the quickfix window
go to preview file, open but maintain focus on ack.vim results
2012-08-16 23:41:25 -04:00
t to open in new tab
2015-02-24 05:45:22 -05:00
T to open in new tab without moving to it
h to open in horizontal split
2015-02-24 05:45:22 -05:00
H to open in horizontal split, keeping focus on the results
2012-08-16 23:41:25 -04:00
v to open in vertical split
2015-02-24 05:45:22 -05:00
gv to open in vertical split, keeping focus on the results
2012-08-16 23:41:25 -04:00
q to close the quickfix window
2014-04-18 08:58:02 -04:00
### Gotchas
2015-02-24 05:45:22 -05:00
Some characters have special meaning, and need to be escaped in your search
pattern. For instance, `#`. You need to escape it with `:Ack '\\\#define
foo'` to search for '#define foo'. See [issue #5].
2014-04-18 08:58:02 -04:00
2015-02-24 05:45:22 -05:00
[issue #5]: https://github.com/mileszs/ack.vim/issues/5
2014-04-18 08:58:02 -04:00
2015-02-24 05:45:22 -05:00
## Possibly FAQ
2014-04-18 08:58:02 -04:00
2015-02-24 05:45:22 -05:00
#### Can I use `ag` ([The Silver Searcher]) with this?
2014-07-02 07:18:18 -04:00
2015-02-24 05:45:22 -05:00
Absolutely, and probably other tools if their output is similar or you can
write a pattern match for it--just set `g:ackprg`. If you like, you can fall
back to Ack in case you use your vimrc on a system without Ag available:
2014-07-02 07:18:18 -04:00
2015-02-24 05:45:22 -05:00
```vim
if executable('ag')
let g:ackprg = 'ag --vimgrep'
endif
```
2014-07-02 07:18:18 -04:00
2015-02-24 05:45:22 -05:00
Since Ack is quite portable you might check a copy of it into your dotfiles
repository in `~/bin` so you'll nearly always have it available.
2014-07-02 07:18:18 -04:00
2015-02-24 05:45:22 -05:00
#### What's the difference from ag.vim?
2014-07-02 07:18:18 -04:00
2015-02-24 05:45:22 -05:00
Well... not a lot really.
2014-07-02 07:18:18 -04:00
2015-02-24 05:45:22 -05:00
Present maintainer, yours truly, [kind of wishes they never forked][sadface],
contributes to both, and wouldn't mind seeing them merged again. ag.vim got a
nice code clean-up (which ack.vim is now hopefully getting), and ack.vim picked
up a few features that haven't made their way to ag.vim, like `:AckWindow`,
optional background search execution with [vim-dispatch], and auto-previewing.
2014-07-02 07:18:18 -04:00
2016-07-16 14:30:35 -04:00
#### I don't want to jump to the first result automatically. ####
Use `:Ack!`, with bang. If you want this behavior most of the time, you might
like an abbreviation or mapping in your personal config, something like these:
```vim
cnoreabbrev Ack Ack!
nnoremap <Leader>a :Ack!<Space>
```
Most of the `:[L]Ack*` commands support this. Note that this behavior follows
the convention of Vim's built-in `:grep` and `:make` commands.
2015-02-24 05:45:22 -05:00
[The Silver Searcher]: https://github.com/ggreer/the_silver_searcher
[sadface]: https://github.com/mileszs/ack.vim/commit/d97090fb502d40229e6976dfec0e06636ba227d5#commitcomment-5771145
2014-07-02 07:18:18 -04:00
2015-02-24 05:45:22 -05:00
## Changelog
2014-07-02 07:18:18 -04:00
2015-02-24 05:45:22 -05:00
Please see [the Github releases page][releases].
2014-07-02 07:18:18 -04:00
2015-02-24 05:45:22 -05:00
## Credits
2014-07-02 07:18:18 -04:00
2015-02-24 05:45:22 -05:00
This plugin is derived from Antoine Imbert's blog post [Ack and Vim
Integration][] (in particular, the function in the update to the post). [Miles
Sterrett][mileszs] packaged it up as a plugin and documented it in Vim's help
format, and since then [many contributors][contributors] have submitted
enhancements and fixes.
2014-07-02 07:18:18 -04:00
2015-02-24 05:45:22 -05:00
And of course, where would we be without [Ack]. And, you know, Vim.
2014-07-02 07:18:18 -04:00
2015-02-24 05:45:22 -05:00
[Ack and Vim Integration]: http://blog.ant0ine.com/typepad/2007/03/ack-and-vim-integration.html
[mileszs]: https://github.com/mileszs
[contributors]: https://github.com/mileszs/ack.vim/graphs/contributors
[Ack]: http://beyondgrep.com/
2014-07-02 07:18:18 -04:00
2015-02-24 05:45:22 -05:00
[vim-dispatch]: https://github.com/tpope/vim-dispatch
[releases]: https://github.com/mileszs/ack.vim/releases