Skip to content

🚜 Vim plugin to improve project searching with tools like ag and rg

License

Notifications You must be signed in to change notification settings

jesseleite/vim-agriculture

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

51 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Vim Agriculture 🚜

A vim plugin to improve the project search experience when using tools like ag and rg.

Rationale

I was inspired by fzf.vim's ability to quickly :Ag search multiple words without quotes, narrow down multiple results in realtime with extended 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'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 ❀️

Installation

Install using vim-plug or similar:

Plug 'jesseleite/vim-agriculture'

Usage

If you are already using 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 <Plug> mappings in your .vimrc:

nmap <Leader>/ <Plug>AgRawSearch
vmap <Leader>/ <Plug>AgRawVisualSelection
nmap <Leader>* <Plug>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 commands. If you wish to customize or disable this behaviour, see fzf.vim's documentation 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 πŸ”¨

About

🚜 Vim plugin to improve project searching with tools like ag and rg

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •