Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wincent/ferret
🐀 Enhanced multi-file search for Vim
https://github.com/wincent/ferret
ack ag ripgrep vim
Last synced: about 15 hours ago
JSON representation
🐀 Enhanced multi-file search for Vim
- Host: GitHub
- URL: https://github.com/wincent/ferret
- Owner: wincent
- License: bsd-2-clause
- Created: 2015-07-05T22:14:55.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2024-03-29T00:00:26.000Z (8 months ago)
- Last Synced: 2024-10-12T06:09:56.139Z (about 1 month ago)
- Topics: ack, ag, ripgrep, vim
- Language: Vim Script
- Homepage:
- Size: 1.35 MB
- Stars: 692
- Watchers: 14
- Forks: 22
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
- awesome-list - ferret - file search for Vim | wincent | 622 | (Vim script)
README
> "ferret (verb)
(ferret something out) search tenaciously for and find something: she had the ability to ferret out the facts."Ferret improves Vim's multi-file search in four ways:
### 1. Powerful multi-file search
Ferret provides an [`:Ack`](#user-content-ack) command for searching across multiple files using ripgrep (https://github.com/BurntSushi/ripgrep), The Silver Searcher (https://github.com/ggreer/the_silver_searcher), or Ack (http://beyondgrep.com/). Support for passing options through to the underlying search command exists, along with the ability to use full regular expression syntax without doing special escaping. On modern versions of Vim (version 8 or higher, or Neovim), searches are performed asynchronously (without blocking the UI).
Shortcut mappings are provided to start an [`:Ack`](#user-content-ack) search (`a`) or to search for the word currently under the cursor (`s`).
Results are normally displayed in the `quickfix` window, but Ferret also provides a [`:Lack`](#user-content-lack) command that behaves like [`:Ack`](#user-content-ack) but uses the `location-list` instead, and a `l` mapping as a shortcut to [`:Lack`](#user-content-lack).
[`:Back`](#user-content-back) and [`:Black`](#user-content-black) are analogous to [`:Ack`](#user-content-ack) and [`:Lack`](#user-content-lack), but scoped to search within currently open buffers only. [`:Quack`](#user-content-quack) is scoped to search among the files currently in the `quickfix` list.
### 2. Streamlined multi-file replace
The companion to [`:Ack`](#user-content-ack) is [`:Acks`](#user-content-acks) (mnemonic: "Ack substitute", accessible via shortcut `r`), which allows you to run a multi-file replace across all the files placed in the `quickfix` window by a previous invocation of [`:Ack`](#user-content-ack) (or [`:Back`](#user-content-back), or [`:Quack`](#user-content-quack)).
Correspondingly, results obtained by [`:Lack`](#user-content-lack) can be targeted for replacement with [`:Lacks`](#user-content-lacks).
### 3. Quickfix listing enhancements
The `quickfix` listing itself is enhanced with settings to improve its usability, and natural mappings that allow quick removal of items from the list (for example, you can reduce clutter in the listing by removing lines that you don't intend to make changes to).
Additionally, Vim's `:cn`, `:cp`, `:cnf` and `:cpf` commands are tweaked to make it easier to immediately identify matches by centering them within the viewport.
### 4. Easy operations on files in the quickfix listing
Finally, Ferret provides a [`:Qargs`](#user-content-qargs) command that puts the files currently in the `quickfix` listing into the `:args` list, where they can be operated on in bulk via the `:argdo` command. This is what's used under the covers on older versions of Vim by [`:Acks`](#user-content-acks) to do its work (on newer versions the built-in `:cdo` or `:cfdo` are used instead).
Ferret also provides a [`:Largs`](#user-content-largs) command, which is a `location-list` analog for [`:Qargs`](#user-content-qargs).
To install Ferret, use your plug-in management system of choice.
If you don't have a "plug-in management system of choice", I recommend Pathogen (https://github.com/tpope/vim-pathogen) due to its simplicity and robustness. Assuming that you have Pathogen installed and configured, and that you want to install Ferret into `~/.vim/bundle`, you can do so with:
```
git clone https://github.com/wincent/ferret.git ~/.vim/bundle/ferret
```Alternatively, if you use a Git submodule for each Vim plug-in, you could do the following after `cd`-ing into the top-level of your Git superproject:
```
git submodule add https://github.com/wincent/ferret.git ~/vim/bundle/ferret
git submodule init
```To generate help tags under Pathogen, you can do so from inside Vim with:
```
:call pathogen#helptags()
```### `:Ack {pattern} {options}`
Searches for {pattern} in all the files under the current directory (see `:pwd`), unless otherwise overridden via {options}, and displays the results in the `quickfix` listing.
`rg` (ripgrep) then `ag` (The Silver Searcher) will be used preferentially if present on the system, because they are faster, falling back to `ack`/`ack-grep` as needed.
On newer versions of Vim (version 8 and above), the search process runs asynchronously in the background and does not block the UI.
Asynchronous searches are preferred because they do not block, despite the fact that Vim itself is single threaded.
The {pattern} is passed through as-is to the underlying search program, and no escaping is required other than preceding spaces by a single backslash. For example, to search for "\bfoo[0-9]{2} bar\b" (ie. using `ag`'s Perl-style regular expression syntax), you could do:
```
:Ack \bfoo[0-9]{2}\ bar\b
```Likewise, {options} are passed through. In this example, we pass the `-w` option (to search on word boundaries), and scope the search to the "foo" and "bar" subdirectories:
```
:Ack -w something foo bar
```As a convenience `a` is set-up ([`(FerretAck)`](#user-content-plugferretack)) as a shortcut to enter `Cmdline-mode` with `:Ack` inserted on the `Cmdline`. Likewise `s` ([`(FerretAckWord)`](#user-content-plugferretackword)) is a shortcut for running [`:Ack`](#user-content-ack) with the word currently under the cursor.
### `:Ack! {pattern} {options}`
Like [`:Ack`](#user-content-ack), but returns all results irrespective of the value of [`g:FerretMaxResults`](#user-content-gferretmaxresults).
### `:Lack {pattern} {options}`
Just like [`:Ack`](#user-content-ack), but instead of using the `quickfix` listing, which is global across an entire Vim instance, it uses the `location-list`, which is a per-window construct.
Note that [`:Lack`](#user-content-lack) always runs synchronously via `:cexpr`.
### `:Lack! {pattern} {options}`
Like [`:Lack`](#user-content-lack), but returns all results irrespective of the value of [`g:FerretMaxResults`](#user-content-gferretmaxresults).
### `:Back {pattern} {options}`
Like [`:Ack`](#user-content-ack), but searches only listed buffers. Note that the search is still delegated to the underlying `'grepprg'` (`rg`, `ag`, `ack` or `ack-grep`), which means that only buffers written to disk will be searched. If no buffers are written to disk, then [`:Back`](#user-content-back) behaves exactly like [`:Ack`](#user-content-ack) and will search all files in the current directory.
### `:Back! {pattern} {options}`
Like [`:Back`](#user-content-back), but returns all results irrespective of the value of [`g:FerretMaxResults`](#user-content-gferretmaxresults).
### `:Black {pattern} {options}`
Like [`:Lack`](#user-content-lack), but searches only listed buffers. As with [`:Back`](#user-content-back), the search is still delegated to the underlying `'grepprg'` (`rg`, `ag`, `ack` or `ack-grep`), which means that only buffers written to disk will be searched. Likewise, If no buffers are written to disk, then [`:Black`](#user-content-black) behaves exactly like [`:Lack`](#user-content-lack) and will search all files in the current directory.
### `:Black! {pattern} {options}`
Like [`:Black`](#user-content-black), but returns all results irrespective of the value of [`g:FerretMaxResults`](#user-content-gferretmaxresults).
### `:Quack {pattern} {options}`
Like [`:Ack`](#user-content-ack), but searches only among files currently in the `quickfix` listing. Note that the search is still delegated to the underlying `'grepprg'` (`rg`, `ag`, `ack` or `ack-grep`), which means that only buffers written to disk will be searched. If no buffers are written to disk, then [`:Quack`](#user-content-quack) behaves exactly like [`:Ack`](#user-content-ack) and will search all files in the current directory.
### `:Quack! {pattern} {options}`
Like [`:Quack`](#user-content-quack), but returns all results irrespective of the value of [`g:FerretMaxResults`](#user-content-gferretmaxresults).
### `:Acks /{pattern}/{replacement}/`
Takes all of the files currently in the `quickfix` listing and performs a substitution of all instances of {pattern} (a standard Vim search `pattern`) by {replacement}.
A typical sequence consists of an [`:Ack`](#user-content-ack) invocation to populate the `quickfix` listing and then [`:Acks`](#user-content-acks) (mnemonic: "Ack substitute") to perform replacements. For example, to replace "foo" with "bar" across all files in the current directory:
```
:Ack foo
:Acks /foo/bar/
```The pattern and replacement are passed through literally to Vim's `:substitute` command, preserving all characters and escapes, including references to matches in the pattern. For example, the following could be used to swap the order of "foo123" and "bar":
```
:Acks /\v(foo\d+)(bar)/\2\1/
```### `:Lacks /{pattern}/{replacement}/`
Takes all of the files in the current `location-list` and performs a substitution of all instances of {pattern} by {replacement}. This is an analog of the [`:Acks`](#user-content-acks) command, but operates on the `location-list` instead of the `quickfix` listing.
Cancels any asynchronous search that may be in progress in the background.
Eagerly populates the `quickfix` (or `location-list`) window with any results that may have been produced by a long-running asynchronous search in progress in the background.
This is a utility function that is used internally when running on older versions of Vim (prior to version 8) but is also generally useful enough to warrant being exposed publicly.
It takes the files currently in the `quickfix` listing and sets them as `:args` so that they can be operated on en masse via the `:argdo` command.
Just like [`:Qargs`](#user-content-qargs), but applies to the current `location-list`.
It takes the files in the current `location-list` and sets them as `:args` so that they can be operated on en masse via the `:argdo` command.
### Circumstances where mappings do not get set up
Note that Ferret will not try to set up the `` mappings if any of the following are true:
- A mapping with the same `{lhs}` already exists.
- An alternative mapping for the same functionality has already been set up from a `.vimrc`.
- The mapping has been suppressed by setting [`g:FerretMap`](#user-content-gferretmap) to 0 in your `.vimrc`.### Mappings specific to the quickfix window
Additionally, Ferret will set up special mappings in `quickfix` listings, unless prevented from doing so by [`g:FerretQFMap`](#user-content-gferretqfmap):
- `d` (`visual-mode`): delete visual selection
- `dd` (`Normal-mode`): delete current line
- `d`{motion} (`Normal-mode`): delete range indicated by {motion}Ferret provides [`(FerretBack)`](#user-content-plugferretback) which can be used to trigger the [`:Back`](#user-content-back) command. To configure a mapping for it, use `:nmap`:
```
nmap fb (FerretBack)
```Ferret provides [`(FerretBlack)`](#user-content-plugferretblack) which can be used to trigger the [`:Black`](#user-content-black) command. To configure a mapping for it, use `:nmap`:
```
nmap fl (FerretBlack)
```Ferret provides [`(FerretBack)`](#user-content-plugferretback) which can be used to trigger the [`:Quack`](#user-content-quack) command. To configure a mapping for it, use `:nmap`:
```
nmap fq (FerretQuack)
```Ferret maps `a` to [`(FerretAck)`](#user-content-plugferretack), which triggers the [`:Ack`](#user-content-ack) command. To use an alternative mapping instead, create a different one in your `.vimrc` instead using `:nmap`:
```
" Instead of a, use x.
nmap x (FerretAck)
```Ferret maps `l` to [`(FerretLack)`](#user-content-plugferretlack), which triggers the [`:Lack`](#user-content-lack) command. To use an alternative mapping instead, create a different one in your `.vimrc` instead using `:nmap`:
```
" Instead of l, use y.
nmap y (FerretLack)
```Ferret maps `s` (mnemonic: "selection) to [`(FerretAckWord)`](#user-content-plugferretackword), which uses [`:Ack`](#user-content-ack) to search for the word currently under the cursor. To use an alternative mapping instead, create a different one in your `.vimrc` instead using `:nmap`:
```
" Instead of s, use z.
nmap z (FerretAckWord)
```Ferret maps `r` (mnemonic: "replace") to [`(FerretAcks)`](#user-content-plugferretacks), which triggers the [`:Acks`](#user-content-acks) command and fills the prompt with the last search term from Ferret. to use an alternative mapping instead, create a different one in your `.vimrc` instead using `:nmap`:
```
" Instead of r, use u.
nmap u (FerretAcks)
```### `g:FerretNvim` (boolean, default: 1)
Controls whether to use Neovim's `job-control` features, when available, to run searches asynchronously. To prevent this from being used, set to 0, in which case Ferret will fall back to the next method in the list (Vim's built-in async primitives -- see [`g:FerretJob`](#user-content-gferretjob) -- which are typically not available in Neovim, so will then fall back to the next available method).
```
let g:FerretNvim=0
```### `g:FerretJob` (boolean, default: 1)
Controls whether to use Vim's `+job` feature, when available, to run searches asynchronously. To prevent `+job` from being used, set to 0, in which case Ferret will fall back to the next available method.
```
let g:FerretJob=0
```### `g:FerretHlsearch` (boolean, default: none)
Controls whether Ferret should attempt to highlight the search pattern when running [`:Ack`](#user-content-ack) or [`:Lack`](#user-content-lack). If left unset, Ferret will respect the current 'hlsearch' setting. To force highlighting on or off irrespective of 'hlsearch', set [`g:FerretHlsearch`](#user-content-gferrethlsearch) to 1 (on) or 0 (off):
```
let g:FerretHlsearch=0
```### `g:FerretAcksCommand` (string, default: "cdo")
Controls the underlying Vim command that [`:Acks`](#user-content-acks) uses to peform substitutions. On versions of Vim that have it, defaults to `:cdo`, which means that substitutions will apply to the specific lines currently in the `quickfix` listing. Can be set to "cfdo" to instead use `:cfdo` (if available), which means that the substitutions will be applied on a per-file basis to all the files in the `quickfix` listing. This distinction is important if you have used Ferret's bindings to delete entries from the listing.
```
let g:FerretAcksCommand='cfdo'
```### `g:FerretLacksCommand` (string, default: "ldo")
Controls the underlying Vim command that [`:Lacks`](#user-content-lacks) uses to peform substitutions. On versions of Vim that have it, defaults to `:ldo`, which means that substitutions will apply to the specific lines currently in the `location-list`. Can be set to "lfdo" to instead use `:lfdo` (if available), which means that the substitutions will be applied on a per-file basis to all the files in the `location-list`. This distinction is important if you have used Ferret's bindings to delete entries from the listing.
```
let g:FerretLacksCommand='lfdo'
```### `g:FerretVeryMagic` (boolean, default: 1)
Controls whether the [`(FerretAcks)`](#user-content-plugferretacks) mapping should populate the command line with the `/\v` "very magic" marker. Given that the argument passed to [`:Acks`](#user-content-acks) is handed straight to Vim, using "very magic" makes it more likely that the (probably Perl-compatible) regular expression used in the initial search can be used directly with Vim's (famously not-Perl-compatible) regular expression engine.
To prevent the automatic use of `/\v`, set this option to 0:
```
let g:FerretVeryMagic=0
```### `g:FerretExecutable` (string, default: "rg,ag,ack,ack-grep")
Ferret will preferentially use `rg`, `ag` and finally `ack`/`ack-grep` (in that order, using the first found executable), however you can force your preference for a specific tool to be used by setting an override in your `.vimrc`. Valid values are a comma-separated list of "rg", "ag", "ack" or "ack-grep". If no requested executable exists, Ferret will fall-back to the next in the default list.
Example:
```
" Prefer `ag` over `rg`.
let g:FerretExecutable='ag,rg'
```### `g:FerretExecutableArguments` (dict, default: {})
Allows you to override the default arguments that get passed to the underlying search executables. For example, to add `-s` to the default arguments passed to `ack` (`--column --with-filename`):
```
let g:FerretExecutableArguments = {
\ 'ack': '--column --with-filename -s'
\ }
```To find out the default arguments for a given executable, see [`ferret#get_default_arguments()`](#user-content-ferretgetdefaultarguments).
### `g:FerretMaxResults` (number, default: 100000)
Controls the maximum number of results Ferret will attempt to gather before displaying the results. Note that this only applies when searching asynchronously; that is, on recent versions of Vim with `+job` support and when [`g:FerretJob`](#user-content-gferretjob) is not set to 0.
The intent of this option is to prevent runaway search processes that produce huge volumes of output (for example, searching for a common string like "test" inside a `$HOME` directory containing millions of files) from locking up Vim.
In the event that Ferret aborts a search that has hit the [`g:FerretMaxResults`](#user-content-gferretmaxresults) limit, a message will be printed prompting users to run the search again with [`:Ack!`](#user-content-ack) or [`:Lack!`](#user-content-lack) if they want to bypass the limit.
### `g:FerretAutojump` (number, default: 1)
Controls whether Ferret will automatically jump to the first found match.
- Set to 0, Ferret will show the search results but perform no jump.
- Set to 1 (the default), Ferret will show the search results and focus the result listing.
- Set to 2, Ferret will show the search results and jump to the first found match.Example override:
```
let g:FerretAutojump=2
```### `g:FerretQFHandler` (string, default: "botright copen")
Allows you to override the mechanism that opens the `quickfix` window to display search results.
### `g:FerretLLHandler` (string, default: "lopen")
Allows you to override the mechanism that opens the `location-list` window to display search results.
### `g:FerretQFOptions` (boolean, default: 1)
Controls whether to set up setting overrides for `quickfix` windows. These are various settings, such as `norelativenumber`, `nolist` and `nowrap`, that are intended to make the `quickfix` window, which is typically very small relative to other windows, more usable.
A full list of overridden settings can be found in [`ferret-overrides`](#user-content-ferret-overrides).
To prevent the custom settings from being applied, set [`g:FerretQFOptions`](#user-content-gferretqfoptions) to 0:
```
let g:FerretQFOptions=0
```### `g:FerretQFMap` (boolean, default: 1)
Controls whether to set up mappings in the `quickfix` results window and `location-list` for deleting results. The mappings include:
- `d` (`visual-mode`): delete visual selection
- `dd` (`Normal-mode`): delete current line
- `d`{motion} (`Normal-mode`): delete range indicated by {motion}To prevent these mappings from being set up, set to 0:
```
let g:FerretQFMap=0
```### `g:FerretLoaded` (any, default: none)
To prevent Ferret from being loaded, set [`g:FerretLoaded`](#user-content-gferretloaded) to any value in your `.vimrc`. For example:
```
let g:FerretLoaded=1
```### `g:FerretLazyInit` (boolean, default: 1)
In order to minimize impact on Vim start-up time Ferret will initialize itself lazily on first use by default. If you wish to force immediate initialization (for example, to cause `'grepprg'` and `'grepformat'` to be set as soon as Vim launches), then set [`g:FerretLazyInit`](#user-content-gferretlazyinit) to 0 in your `.vimrc`:
```
let g:FerretLazyInit=0
```### `g:FerretCommandNames` (dictionary, default: {})
Ferret's command names are mostly chosen because the plugin started as a simple `ack` wrapper. As related commands were added over time, a pattern involving common suffixes evolved, to make the commands easy to remember (even once Ferret started offering support for non-`ack` tools, such as `ag` and `rg`). As such, [`:Ack`](#user-content-ack), [`:Back`](#user-content-back), [`:Black`](#user-content-black), [`:Lack`](#user-content-lack), and [`:Quack`](#user-content-quack) are all commands, as are the variants [`:Acks`](#user-content-acks) and [`:Lacks`](#user-content-lacks), along with [`:Qargs`](#user-content-qargs) and [`:Largs`](#user-content-largs). Exceptions to the pattern are [`:FerretCancelAsync`](#user-content-ferretcancelasync) and [`:FerretPullAsync`](#user-content-ferretpullasync).
Should you wish to override any or all of these names, you may define [`g:FerretCommandNames`](#user-content-gferretcommandnames) early on in your `.vimrc` (before Ferret is loaded), and it will use the specified names instead, falling back to the defaults for any undefined commands. For example, to use `:Rg` in place of the [`:Ack`](#user-content-ack) command, and `:Rgb` in place of [`:Back`](#user-content-back), but keep using the standard names for all other commands, you would write:
```
let g:FerretCommandNames={'Ack': 'Rg', 'Back': 'Rgb'}
```Overriding may be useful to avoid conflicts with other plug-ins that compete to define commands with the same names, or simply to match personal preferences.
### `g:FerretAckWordWord` (boolean, default: 0)
When set to 1, passes the `-w` option to the underlying search tool whenever [`(FerretAckWord)`](#user-content-plugferretackword) is pressed. This forces the tool to match only on word boundaries (ie. analagous to Vim's `star` mapping).
The default is 0, which means the `-w` option is not passed and matches need not occur on word boundaries (ie. analagous to Vim's `gstar` mapping).
To override the default:
```
let g:FerretAckWordWord=1
```### `g:FerretMap` (boolean, default: 1)
Controls whether to set up the Ferret mappings, such as [`(FerretAck)`](#user-content-plugferretack) (see [`ferret-mappings`](#user-content-ferret-mappings) for a full list). To prevent any mapping from being configured, set to 0:
```
let g:FerretMap=0
```### `g:FerretQFCommands` (boolean, default: 1)
Controls whether to set up custom versions of the `quickfix` commands, `:cn`, `:cnf`, `:cp` an `:cpf`. These overrides vertically center the match within the viewport on each jump. To prevent the custom versions from being configured, set to 0:
```
let g:FerretQFCommands=0
```### `g:FerretFormat` (string, default: "%f:%l:%c:%m")
Sets the '`grepformat`' used by Ferret.
ferret#get_default_arguments()
### `ferret#get_default_arguments()`
Call this with an executable name to find out the default arguments that will be passed when invoking that executable. For example:
```
echo ferret#get_default_arguments('rg')
```This may be useful if you wish to extend or otherwise modify the arguments by setting [`g:FerretExecutableArguments`](#user-content-gferretexecutablearguments).
FerretAsyncFinish
FerretAsyncStart
FerretDidWrite
FerretWillWrite
For maximum compatibility with other plug-ins, Ferret runs the following "User" autocommands before and after running the file writing operations during [`:Acks`](#user-content-acks) or [`:Lacks`](#user-content-lacks):
- FerretWillWrite
- FerretDidWriteFor example, to call a pair of custom functions in response to these events, you might do:
```
autocmd! User FerretWillWrite
autocmd User FerretWillWrite call CustomWillWrite()
autocmd! User FerretDidWrite
autocmd User FerretDidWrite call CustomDidWrite()
```Additionally, Ferret runs these autocommands when an async search begins and ends:
- FerretAsyncStart
- FerretAsyncFinishFerret overrides the 'grepformat' and 'grepprg' settings, preferentially setting `rg`, `ag`, `ack` or `ack-grep` as the 'grepprg' (in that order) and configuring a suitable 'grepformat'.
Additionally, Ferret includes an `ftplugin` for the `quickfix` listing that adjusts a number of settings to improve the usability of search results.
Turned off to reduce visual clutter in the search results, and because 'list' is most useful in files that are being actively edited, which is not the case for `quickfix` results.
Turned off, because it is more useful to have a sense of absolute progress through the results list than to have the ability to jump to nearby results (especially seeing as the most common operations are moving to the next or previous file, which are both handled nicely by `:cnf` and `:cpf` respectively).
Turned off to avoid ugly wrapping that makes the results list hard to read, and because in search results, the most relevant information is the filename, which is on the left and is usually visible even without wrapping.
Turned on to give a sense of absolute progress through the results.
Set to 0 because the `quickfix` listing is usually small by default, so trying to keep the current line away from the edge of the viewpoint is futile; by definition it is usually near the edge.
Turned off to reduce visual clutter.
To prevent any of these `quickfix`-specific overrides from being set up, you can set [`g:FerretQFOptions`](#user-content-gferretqfoptions) to 0 in your `.vimrc`:
```
let g:FerretQFOptions=0
```### Ferret fails to find patterns containing spaces
As described in the documentation for [`:Ack`](#user-content-ack), the search pattern is passed through as-is to the underlying search command, and no escaping is required other than preceding spaces by a single backslash.
So, to find "foo bar", you would search like:
```
:Ack foo\ bar
```Unescaped spaces in the search are treated as argument separators, so a command like the following means pass the `-w` option through, search for pattern "foo", and limit search to the "bar" directory:
```
:Ack -w foo bar
```Note that wrapping in quotes will probably not do what you want.
This, for example, is a search for `"foo` in the `bar"` directory:
```
:Ack "foo bar"
```and this is a search for `'abc` in the `xyz'` directory:
```
:Ack 'abc xyz'
```This approach to escaping is taken in order to make it straightfoward to use powerful Perl-compatible regular expression syntax in an unambiguous way without having to worry about shell escaping rules; for example:
```
:Ack \blog\((['"]).*?\1\) -i --ignore-dir=src/vendor src dist build
```### Why do Ferret commands start with "Ack", "Lack" and so on?
Ferret was originally the thinnest of wrappers (7 lines of code in my `.vimrc`) around `ack`. The earliest traces of it can be seen in the initial commit to my dotfiles repo in May, 2009 (https://wincent.dev/h).
So, even though Ferret has a new name now and actually prefers `rg` then `ag` over `ack`/`ack-grep` when available, I prefer to keep the command names intact and benefit from years of accumulated muscle-memory.
Just as Ferret aims to improve the multi-file search and replace experience, Loupe does the same for within-file searching:
https://github.com/wincent/loupe
Source code:
https://github.com/wincent/ferret
Official releases are listed at:
http://www.vim.org/scripts/script.php?script_id=5220
Copyright 2015-present Greg Hurrell. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Patches can be sent via mail to [email protected], or as GitHub pull requests at: https://github.com/wincent/ferret/pulls
At the moment the release process is manual:
- Perform final sanity checks and manual testing
- Update the [`ferret-history`](#user-content-ferret-history) section of the documentation
- Verify clean work tree:```
git status
```- Tag the release:
```
git tag -s -m "$VERSION release" $VERSION
```- Publish the code:
```
git push origin main --follow-tags
git push github main --follow-tags
```- Produce the release archive:
```
git archive -o ferret-$VERSION.zip HEAD -- .
```- Upload to http://www.vim.org/scripts/script.php?script_id=5220
Ferret is written and maintained by Greg Hurrell <[email protected]>.
Other contributors that have submitted patches include (in alphabetical order):
- Andrew Macpherson
- Daniel Silva
- Filip Szymański
- Joe Lencioni
- Jon Parise
- Nelo Wallus
- Tom Dooner
- Vaibhav Sagar
- Yoni Weill
- fentThis list produced with:
```
:read !git shortlog -s HEAD | grep -v 'Greg Hurrell' | cut -f 2-3 | sed -e 's/^/- /'
```- Add [`(FerretBack)`](#user-content-plugferretback), [`(FerretBlack)`](#user-content-plugferretblack), and [`(FerretQuack)`](#user-content-plugferretquack) targets for use in mappings (https://github.com/wincent/ferret/issues/79).
- Fix hangs produced by options that take arguments in `rg` v13.0.0 (https://github.com/wincent/ferret/issues/82).
- Fix `E42` and `E684` errors when deleting last item in listing, or trying to delete from an empty listing (https://github.com/wincent/ferret/issues/83).
- Add [`g:FerretCommandNames`](#user-content-gferretcommandnames) (https://github.com/wincent/ferret/issues/75).- Add [`g:FerretAckWordWord`](#user-content-gferretackwordword) setting, to pass `-w` to the underlying search tool when [`(FerretAckWord)`](#user-content-plugferretackword) is pressed (https://github.com/wincent/ferret/issues/66).
- Use `:normal!` instead of `:normal` to avoid running custom mappings (patch from Yoni Weill, https://github.com/wincent/ferret/pull/67).
- Append a trailing slash when autocompleting a directory name (https://github.com/wincent/ferret/issues/69).
- Fixed failure to detect pre-existing mapping to [`(FerretLack)`](#user-content-plugferretlack).
- Worked around breakage caused by `rg` v13.0.0 (https://github.com/wincent/ferret/issues/78).- The [`(FerretAcks)`](#user-content-plugferretacks) mapping now uses `/\v` "very magic" mode by default. This default can be changed using the [`g:FerretVeryMagic`](#user-content-gferretverymagic) option.
- [`:Acks`](#user-content-acks) now preferentially uses `:cdo` (rather than `:cfdo`) to make replacements, which means that it no longer operates on a per-file level and instead targets individual entries within the `quickfix` window. This is relevant if you've used Ferrets mappings to delete entries from the window. The old behavior can be restored with the [`g:FerretAcksCommand`](#user-content-gferretackscommand) option.
- Ferret now has a [`:Lacks`](#user-content-lacks) command, an analog to [`:Acks`](#user-content-acks) which applies to the `location-list`.
- Likewise, Ferret now has a [`:Largs`](#user-content-largs) command, analogous to [`:Qargs`](#user-content-qargs), which applies to the `location-list` instead of the `quickfix` window.
- The Ferret bindings that are set-up in the `quickfix` window when [`g:FerretQFMap`](#user-content-gferretqfmap) is enabled now also apply to the `location-list`.- Added [`:Quack`](#user-content-quack) command, analogous to [`:Ack`](#user-content-ack) but scoped to the files currently listed in the `quickfix` window.
- Fixed option autocompletion.- Restore compatibility with versions of `rg` prior to v0.8 (https://github.com/wincent/ferret/issues/59).
- Make [`:Acks`](#user-content-acks) behavior the same irrespective of the `'gdefault'` setting.
- Try to avoid "press ENTER to continue" prompts.
- Put search term in `w:quickfix_title` for use in statuslines (https://github.com/wincent/ferret/pull/57).
- Add [`g:FerretExecutableArguments`](#user-content-gferretexecutablearguments) and [`ferret#get_default_arguments()`](#user-content-ferretgetdefaultarguments) (https://github.com/wincent/ferret/pull/46).- Fix for [`:Lack`](#user-content-lack) results opening in quickfix listing in Neovim (https://github.com/wincent/ferret/issues/47).
- Fix broken [`:Back`](#user-content-back) and [`:Black`](#user-content-black) commands (https://github.com/wincent/ferret/issues/48).
- Fix failure to handle search patterns containing multiple escaped spaces (https://github.com/wincent/ferret/issues/49).
- Improve handling of backslash escapes (https://github.com/wincent/ferret/issues/41).
- Add [`g:FerretAutojump`](#user-content-gferretautojump).
- Drop support for vim-dispatch.- Add support for Neovim, along with [`g:FerretNvim`](#user-content-gferretnvim) setting.
### 1.5 "Cinco de Cuatro" (4 May 2017)
- Improvements to the handling of very large result sets (due to wide lines or many results).
- Added [`g:FerretLazyInit`](#user-content-gferretlazyinit).
- Added missing documentation for [`g:FerretJob`](#user-content-gferretjob).
- Added [`g:FerretMaxResults`](#user-content-gferretmaxresults).
- Added feature-detection for `rg` and `ag`, allowing Ferret to gracefully work with older versions of those tools that do not support all desired command-line switches.- Drop broken support for `grep`, printing a prompt to install `rg`, `ag`, or `ack`/`ack-grep` instead.
- If an `ack` executable is not found, search for `ack-grep`, which is the name used on Debian-derived distros.- Reset `'errorformat'` before each search (fixes issue #31).
- Added [`:Back`](#user-content-back) and [`:Black`](#user-content-black) commands, analogous to [`:Ack`](#user-content-ack) and [`:Lack`](#user-content-lack) but scoped to search within currently open buffers only.
- Change [`:Acks`](#user-content-acks) to use `:cfdo` when available rather than [`:Qargs`](#user-content-qargs) and `:argdo`, to avoid polluting the `arglist`.
- Remove superfluous `QuickFixCmdPost` autocommands, resolving clash with Neomake plug-in (patch from Tom Dooner, #36).
- Add support for searching with ripgrep (`rg`).- Add optional support for running searches asynchronously using Vim's `+job` feature (enabled by default in sufficiently recent versions of Vim); see [`g:FerretJob`](#user-content-gferretjob), [`:FerretCancelAsync`](#user-content-ferretcancelasync) and [`:FerretPullAsync`](#user-content-ferretpullasync).
- Fix another edge case when searching for patterns containing "#", only manifesting under dispatch.vim.
- Fix edge case when searching for strings of the form "<foo>".
- Fix edge case when searching for patterns containing "#" and "%".
- Provide completion for `ag` and `ack` options when using [`:Ack`](#user-content-ack) and [`:Lack`](#user-content-lack).
- Fix display of error messages under dispatch.vim.- Fix broken [`:Qargs`](#user-content-qargs) command (patch from Daniel Silva).
- Add [`g:FerretQFHandler`](#user-content-gferretqfhandler) and [`g:FerretLLHandler`](#user-content-gferretllhandler) options (patch from Daniel Silva).
- Make `` mappings accessible even [`g:FerretMap`](#user-content-gferretmap) is set to 0.
- Fix failure to report filename when using `ack` and explicitly scoping search to a single file (patch from Daniel Silva).
- When using `ag`, report multiple matches per line instead of just the first (patch from Daniel Silva).
- Improve content and display of error messages.- Added highlighting of search pattern and related [`g:FerretHlsearch`](#user-content-gferrethlsearch) option (patch from Nelo-Thara Wallus).
- Add better error reporting for failed or incorrect searches.- Added [`FerretDidWrite`](#user-content-ferretdidwrite) and [`FerretWillWrite`](#user-content-ferretwillwrite) autocommands (patch from Joe Lencioni).
- Add [`(FerretAcks)`](#user-content-plugferretacks) mapping (patch from Nelo-Thara Wallus).- Initial release, extracted from my dotfiles (https://github.com/wincent/wincent).