Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jesseleite/vim-agriculture
🚜 Vim plugin to improve project searching with tools like ag and rg
https://github.com/jesseleite/vim-agriculture
ack ag fzf search vim
Last synced: 2 months ago
JSON representation
🚜 Vim plugin to improve project searching with tools like ag and rg
- Host: GitHub
- URL: https://github.com/jesseleite/vim-agriculture
- Owner: jesseleite
- License: mit
- Created: 2018-02-27T00:23:32.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-05-12T16:29:43.000Z (8 months ago)
- Last Synced: 2024-10-14T10:49:13.486Z (3 months ago)
- Topics: ack, ag, fzf, search, vim
- Language: Vim script
- Homepage:
- Size: 30.3 KB
- Stars: 137
- Watchers: 5
- Forks: 11
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Vim Agriculture 🚜
A vim plugin to improve the project search experience when using tools like [ag](https://github.com/ggreer/the_silver_searcher) and [rg](https://github.com/BurntSushi/ripgrep).
- [Rationale](#rationale)
- [Installation](#installation)
- [Usage](#usage)
- [Mappings](#mappings)
- [Customization](#customization)
- [How It Works](#how-it-works)## Rationale
I was inspired by [fzf.vim](https://github.com/junegunn/fzf.vim)'s ability to quickly `:Ag` search multiple words without quotes, narrow down multiple results in realtime with [extended search syntax](https://github.com/junegunn/fzf#search-syntax), then populate quickfix for a large refactor 👌
```
:Ag function index
```But I found myself missing the ability to pass command line options like I could with [ack.vim](https://github.com/mileszs/ack.vim)'s `:Ack` 😢
```
:Ack -Q -i 'function index' vendor
```Furthermore, fzf.vim's `:Ag` treats quotes as a literal part of the search query, which is inconsistent with `ag` on the command line.
Thus, the intention of this plugin is to bring the best of both worlds to your favourite search wrapper. Perform multi-word searches with or without quotes, pass command line options, and do it all from one command.
[Read more about my project searching workflow with fzf.vim and agriculture](https://jesseleite.com/posts/4/project-search-your-feelings) ❤️
## Installation
Install using [vim-plug](https://github.com/junegunn/vim-plug) or similar:
```
Plug 'jesseleite/vim-agriculture'
```## Usage
If you are already using [fzf.vim](https://github.com/junegunn/fzf.vim), you can use the provided `:AgRaw` / `:RgRaw` commands.
```
:AgRaw func.*index
:AgRaw 'func.*index'
:AgRaw -Q 'function index()' app/Http/Controllers
```Likewise for `:RgRaw`, just substitute `AgRaw` in `RgRaw` in the above examples.
If you are using another search wrapper, you'll need to wrap your input with `agriculture#smart_quote_input()`.
## Mappings
If you are using one of the provided commands, you can hook into the provided `` mappings in your `.vimrc`:
```
nmap / AgRawSearch
vmap / AgRawVisualSelection
nmap * AgRawWordUnderCursor
```Likewise for `:RgRaw`, just substitute `AgRaw` in `RgRaw` in the above examples.
## Customization
### Command Line Options
If you are using one of the provided commands, you can also set default command line options in your `.vimrc`:
```
let g:agriculture#ag_options = '--case-sensitive'
```Again likewise for `:RgRaw` with `g:agriculture#rg_options`.
### Disable Smart Quoting
If you are using one of the provided commands, and want to disable smart quoting for CLI consistency:
```
let g:agriculture#disable_smart_quoting = 1
```### Preview Window
Preview windows are now rendered by default in many [fzf.vim](https://github.com/junegunn/fzf.vim) commands. If you wish to customize or disable this behaviour, [see fzf.vim's documentation](https://github.com/junegunn/fzf.vim#preview-window) on preview windows.
## How It Works
Your input will be automatically quoted _unless_ the following conditions are met:
- Quotes in your query, signifying you might want to handle your own quoting/escaping, ie.
```
:Ag -Q "Already quoted this pattern."
:Ag Why you "scruffy looking nerf herder"!
:Ag Who's scruffy looking?
```
- A space followed by a dash in your query, signifying you might be passing an option, ie.
```
:Ag -Q function index
:Ag Which way to the beach? -> that way!
```
- An escaped pattern followed by an unescaped space, signifying you might be passing a path, ie.
```
:Ag an\ escaped\ pattern vendor/folder
```TL;DR: If you use quotes, dashes, or need to pass a path, it's recommended you quote/escape your own pattern and vim-agriculture will stay out of your way 👍
## Who am I?
Just a hack 🔨
- [jesseleite.com](https://jesseleite.com)
- [@jesseleite85](https://twitter.com/jesseleite85)