Giter VIP home page Giter VIP logo

vim-agriculture's Introduction

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 ๐Ÿ”จ

vim-agriculture's People

Contributors

jesseleite avatar rperryng avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.