/README.md

https://github.com/chrisjohnson/vim-grep · Markdown · 94 lines · 67 code · 27 blank · 0 comment · 0 complexity · 2b7331c387de5f829eb2f1d46cec3b6d MD5 · raw file

  1. # Grep
  2. A utility for grepping that isn't limited to a specific program
  3. ## Selection
  4. - `grep.vim` will try to use `rg` if available.
  5. - If `rg` is unavailable, and the file is in a git repo, `git-grep` will be used.
  6. - If not, it will fallback to `ag`.
  7. - If `ag` is unavailable, `grep` will be used.
  8. **Note** This will clobber your `g:grepprg` by overwriting it whenever `:Grep` is
  9. called with the appropriate tool based on the file and your environment.
  10. ## Installation
  11. Pick one of the supported alternatives: `rg`, `ag` and `git-grep`
  12. ### Rg
  13. You have to install [rg](https://github.com/BurntSushi/ripgrep), of
  14. course.
  15. Install with Homebrew:
  16. ```bash
  17. brew install rg
  18. ```
  19. ### Ag
  20. You have to install [ag](https://github.com/ggreer/the_silver_searcher), of
  21. course.
  22. Install with Homebrew:
  23. ```bash
  24. brew install the_silver_searcher
  25. ```
  26. ### Git grep
  27. This comes with git, and will automatically be used when appropriate
  28. ## Usage
  29. `:Grep [options] {pattern} [{directory}]`
  30. Search recursively in {directory} (which defaults to the current directory) for
  31. the {pattern}.
  32. Files containing the search term will be listed in the split window, along with
  33. the line number of the occurrence, once for each occurrence. [Enter] on a line
  34. in this window will open the file, and place the cursor on the matching line.
  35. Just like where you use :grep, :grepadd, :lgrep, and :lgrepadd, you can use
  36. `:Grep`, `:GrepAdd`, `:LGrep`, and `:LGrepAdd` respectively.
  37. This plugin is almost copy and pasted from [mileszs' ack.vim
  38. plugin](https://github.com/mileszs/ack.vim).
  39. ## Motion
  40. Motions to grep for things. Works with pretty much everything, including:
  41. ```
  42. w, W, e, E, b, B, t*, f*, i*, a*, and custom text objects
  43. ```
  44. ### Normal mode
  45. Place your cursor somewhere, type `gr` and, then perform a text-object for what
  46. you want to grep for.
  47. ### Visual mode
  48. Visually select the pattern you want to grep for, type `gr`.
  49. ### Mappings
  50. The mapping `gr` is set in both normal and visual-mode, if you want to remove it
  51. to set your own mappings you set `g:grep_no_maps` in your `.vimrc`
  52. If you want to use `qq` instead of `gr`:
  53. ```viml
  54. let g:grep_no_maps = 1
  55. nnoremap <silent> qq :set opfunc=<SID>GrepMotion<CR>g@
  56. xnoremap <silent> qq :<C-U>call <SID>GrepMotion(visualmode())<CR>
  57. ```
  58. ## Customizing
  59. The following options allow customization of the commands.
  60. ```viml
  61. let g:vimgrep_rg_command="rg --vimgrep --color=never --no-heading --hidden"
  62. let g:vimgrep_ag_command="ag --vimgrep --color=never --column --hidden"
  63. let g:vimgrep_gitgrep_command="git --no-pager grep -n"
  64. ```
  65. # License
  66. Copyright (c) Teo Ljungberg. Distributed under the same terms as Vim itself. See
  67. `:help license`.