/README.md

https://github.com/jesseleite/vim-agriculture · Markdown · 116 lines · 78 code · 38 blank · 0 comment · 0 complexity · ff421abb591d74718851494a3a145903 MD5 · raw file

  1. # Vim Agriculture 🚜
  2. 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).
  3. - [Rationale](#rationale)
  4. - [Installation](#installation)
  5. - [Usage](#usage)
  6. - [Mappings](#mappings)
  7. - [Customization](#customization)
  8. - [How It Works](#how-it-works)
  9. ## Rationale
  10. 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 👌
  11. ```
  12. :Ag function index
  13. ```
  14. 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` 😢
  15. ```
  16. :Ack -Q -i 'function index' vendor
  17. ```
  18. Furthermore, fzf.vim's `:Ag` treats quotes as a literal part of the search query, which is inconsistent with `ag` on the command line.
  19. 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.
  20. [Read more about my project searching workflow with fzf.vim and agriculture](https://jesseleite.com/posts/4/project-search-your-feelings) ❤️
  21. ## Installation
  22. Install using [vim-plug](https://github.com/junegunn/vim-plug) or similar:
  23. ```
  24. Plug 'jesseleite/vim-agriculture'
  25. ```
  26. ## Usage
  27. If you are already using [fzf.vim](https://github.com/junegunn/fzf.vim), you can use the provided `:AgRaw` / `:RgRaw` commands.
  28. ```
  29. :AgRaw func.*index
  30. :AgRaw 'func.*index'
  31. :AgRaw -Q 'function index()' app/Http/Controllers
  32. ```
  33. Likewise for `:RgRaw`, just substitute `AgRaw` in `RgRaw` in the above examples.
  34. If you are using another search wrapper, you'll need to wrap your input with `agriculture#smart_quote_input()`.
  35. ## Mappings
  36. If you are using one of the provided commands, you can hook into the provided `<Plug>` mappings in your `.vimrc`:
  37. ```
  38. nmap <Leader>/ <Plug>AgRawSearch
  39. vmap <Leader>/ <Plug>AgRawVisualSelection
  40. nmap <Leader>* <Plug>AgRawWordUnderCursor
  41. ```
  42. Likewise for `:RgRaw`, just substitute `AgRaw` in `RgRaw` in the above examples.
  43. ## Customization
  44. ### Command Line Options
  45. If you are using one of the provided commands, you can also set default command line options in your `.vimrc`:
  46. ```
  47. let g:agriculture#ag_options = '--case-sensitive'
  48. ```
  49. Again likewise for `:RgRaw` with `g:agriculture#rg_options`.
  50. ### Disable Smart Quoting
  51. If you are using one of the provided commands, and want to disable smart quoting for CLI consistency:
  52. ```
  53. let g:agriculture#disable_smart_quoting = 1
  54. ```
  55. ### Preview Window
  56. 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.
  57. ## How It Works
  58. Your input will be automatically quoted _unless_ the following conditions are met:
  59. - Quotes in your query, signifying you might want to handle your own quoting/escaping, ie.
  60. ```
  61. :Ag -Q "Already quoted this pattern."
  62. :Ag Why you "scruffy looking nerf herder"!
  63. :Ag Who's scruffy looking?
  64. ```
  65. - A space followed by a dash in your query, signifying you might be passing an option, ie.
  66. ```
  67. :Ag -Q function index
  68. :Ag Which way to the beach? -> that way!
  69. ```
  70. - An escaped pattern followed by an unescaped space, signifying you might be passing a path, ie.
  71. ```
  72. :Ag an\ escaped\ pattern vendor/folder
  73. ```
  74. 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 👍
  75. ## Who am I?
  76. Just a hack 🔨
  77. - [jesseleite.com](https://jesseleite.com)
  78. - [@jesseleite85](https://twitter.com/jesseleite85)