ack2vim eases the interface beween ack and vim, so that ack
's findings can be found with vim
as well.
It helps by running ack
commands, gathering the results and using vim
to edit any found files, and telling vim
to search for similar strings to those ack
sought. The strings vim
searches for are "similar", not "the same", because the two commands use different regexp languages, so ack2vim converts the strings.
ack2vim is useful at the bash command line, it is not used within vim
.
ack2vim allows lines in bash
like
ap -w main -v
which tells ack
to search all python files for the word main, and tells vim
to open all those files searching for the word main
And it allows lines like
vai sys
which searches all python files for any "import sys" or "from sys import", and vims those files with that search
Clone the repository and source a file to add ack2vim's command into bash
git clone https://github.com/jalanb/ack2vim.git
source ack2vim/ack2vim
Merge ack2vim's ackrc file into ack
's config file in $HOME
vim -d ack2vim/ackrc ~/.ackrc
Because it needs to handle options for both ack
and vim
, ack2vim does not provide any options itself. Rather it provides individual commands, such as the following which add filetype options to the ack
command line
command | filetype |
---|---|
aa | --all |
ac | --code |
ae | --erl |
al | --html |
ap | --python |
at | --pyt |
(These filetypes are defined in the ackrc file included in this repository)
Some commands add other options, e.g. ai
searches in python files for imports only. RTFS for more commands
Each a...
command has a matching va...
command which runs the ack
command, and sends the results on to vim
. And, for the convenience of those using readline
's vi mode at the command line, each also has an equivalent aa...
alias.
So, to search for "fred" using ack
the command is the usual
ack fred
Or, to search only in web files:
al fred
To do the same searches, and then open the results in vim
the commands would be
vack fred
val fred
or, equivalently
aack fred
aal fred
ack2vim provides bash functions with abbreviated names, all of which eventually hand over to a python program which interprets arguments, and does some conversion of ack
to vim
regexps, before sending the correct vim
command to stdout. Bash captures that and runs it.
- ack2vim only provides the commands I have needed - searching in shell, python, and web files. But they are very easy to extend
- ack2vim needs to handle options from the shell command line for both
ack
andvim
. The code which handles this is a "good enough" hack
Although this code was originally forked from viack we have diverged completely, hence the copyright claim in the LICENSE file
This code WFM and I use it daily, but caveat lector