From 8417396e3f441ec85ffcd9260e19e4d0a00cb243 Mon Sep 17 00:00:00 2001 From: Scott Pierce Date: Fri, 6 Aug 2021 15:02:05 -0500 Subject: [PATCH] Use `ripgrep` instead of `ag` as default grep program Resolves: https://github.com/ddrscott/vim-side-search/issues/10 --- README.md | 35 +++++++++++++++++++++-------------- ftdetect/ag.vim | 1 - ftdetect/rg.vim | 1 + plugin/side-search.vim | 8 ++++++-- syntax/ag.vim | 9 --------- syntax/rg.vim | 8 ++++++++ 6 files changed, 36 insertions(+), 26 deletions(-) delete mode 100644 ftdetect/ag.vim create mode 100644 ftdetect/rg.vim delete mode 100644 syntax/ag.vim create mode 100644 syntax/rg.vim diff --git a/README.md b/README.md index cda48cd..d69c973 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,14 @@ ## Overview The `quickfix` window is great, but it would be nice to get some context around -our searches. This plugin adds `ag` output to a side buffer with quick +our searches. This plugin adds `rg` output to a side buffer with quick navigation mappings using comfortable Vim conventions. ![Simple Demo](side-search-demo.gif) ## Features -- step through `ag` output instead of `quickfix` output -- syntax highlighting of `ag` output -- mappable to search current word under cursor +- step through `rg` output instead of `quickfix` output +- syntax highlighting of `rg` output +- mappable to search current word under the cursor - configurable `g:side_search_prg` similar to `grepprg` - vertical or horizontal split output via `g:side_search_splitter` @@ -23,27 +23,27 @@ qf - :grep! to Quickfix ## Prerequisites We rely on [The Silver Searcher](https://github.com/ggreer/the_silver_searcher) -to perform our file/text searches for us. Theoretically any program which has -the same output could also work, but that we only test using `ag` output. +to perform our file/text searches for us. Theoretically, any program which has +the same output could also work, but that we only test using `rg` output. -To install `ag` command on OSX: +To install `rg` command on OSX: ```sh -brew install the_silver_searcher +brew install ripgrep ``` -For refer to -[The Silver Searcher](https://github.com/ggreer/the_silver_searcher) -for more instructions. +Refer to [Ripgrep](https://github.com/BurntSushi/ripgrep) for more instructions. ## Global Configuration ```vim " How should we execute the search? " --heading and --stats are required! -let g:side_search_prg = 'ag --word-regexp' +let g:side_search_prg = 'rg --word-regexp' \. " --ignore='*.js.map'" \. " --heading --stats -B 1 -A 4" + \. " --case-sensitive" + \. " --line-number" " Can use `vnew` or `new` let g:side_search_splitter = 'vnew' @@ -74,9 +74,16 @@ Surround terms with double quotes :SideSearch "cats and dogs" ``` -> How to pass extra args to `ag`? +> How to pass extra args to `rg`? Just do it :) ``` -:SideSearch --js MyAwesomeComponent +:SideSearch -t js MyAwesomeComponent ``` + +> What happened to using The Silver Searcher? + +The `ag` program was deprecated back in 2016. https://github.com/rking/ag.vim/issues/124 +We moved to `ripgrep` as a modern alternative. +Ultimately, any program can be used by setting `g:side_search_prg` and has output matching out syntax highlighter should +work. diff --git a/ftdetect/ag.vim b/ftdetect/ag.vim deleted file mode 100644 index 5942a34..0000000 --- a/ftdetect/ag.vim +++ /dev/null @@ -1 +0,0 @@ -au BufNewFile,BufRead *.ag set filetype=ag diff --git a/ftdetect/rg.vim b/ftdetect/rg.vim new file mode 100644 index 0000000..829e314 --- /dev/null +++ b/ftdetect/rg.vim @@ -0,0 +1 @@ +au BufNewFile,BufRead *.rg set filetype=rg diff --git a/plugin/side-search.vim b/plugin/side-search.vim index 6b4f7a7..fcf77cf 100644 --- a/plugin/side-search.vim +++ b/plugin/side-search.vim @@ -55,7 +55,11 @@ endfunction function! s:defaults() abort if !exists('g:side_search_prg') - let g:side_search_prg = 'ag --word-regexp --heading --stats -C 2 --group' + if executable('rg') + let g:side_search_prg = 'rg --word-regexp --heading --stats -C 2 --case-sensitive --line-number' + else + let g:side_search_prg = 'ag --word-regexp --heading --stats -C 2 --group' + endif endif if !exists('g:side_search_splitter') let g:side_search_splitter = 'vnew' @@ -218,7 +222,7 @@ function! SideSearch(args) abort call feedkeys(":let &hlsearch=1 \| echo \", 'n') " set this stuff after execute for better performance - setlocal nomodifiable filetype=ag + setlocal nomodifiable filetype=rg endfunction " Create a command to call SideSearch diff --git a/syntax/ag.vim b/syntax/ag.vim deleted file mode 100644 index e9522e1..0000000 --- a/syntax/ag.vim +++ /dev/null @@ -1,9 +0,0 @@ -syntax match agPath "\v^(\d+[:-])@!.+$" -highlight link agPath Directory - -syntax match agContext "\v^(\d+\-).*$" -highlight link agContext Comment - -syntax match agComment "\v^[#-].*" -highlight link agComment Comment - diff --git a/syntax/rg.vim b/syntax/rg.vim new file mode 100644 index 0000000..c8793de --- /dev/null +++ b/syntax/rg.vim @@ -0,0 +1,8 @@ +syntax match rgPath "\v^(\d+[:-])@!.+$" +highlight link rgPath Directory + +syntax match rgContext "\v^(\d+\-).*$" +highlight link rgContext Comment + +syntax match rgComment "\v^[#-].*" +highlight link rgComment Comment