Skip to content

Commit

Permalink
Merge pull request #11 from ddrscott/use-ripgrep
Browse files Browse the repository at this point in the history
Use `ripgrep` instead of `ag` as default grep program
  • Loading branch information
ddrscott authored Aug 6, 2021
2 parents be409b2 + 8417396 commit ce47a04
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 26 deletions.
35 changes: 21 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -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`

Expand All @@ -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'
Expand Down Expand Up @@ -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.
1 change: 0 additions & 1 deletion ftdetect/ag.vim

This file was deleted.

1 change: 1 addition & 0 deletions ftdetect/rg.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
au BufNewFile,BufRead *.rg set filetype=rg
8 changes: 6 additions & 2 deletions plugin/side-search.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -218,7 +222,7 @@ function! SideSearch(args) abort
call feedkeys(":let &hlsearch=1 \| echo \<CR>", 'n')

" set this stuff after execute for better performance
setlocal nomodifiable filetype=ag
setlocal nomodifiable filetype=rg
endfunction

" Create a command to call SideSearch
Expand Down
9 changes: 0 additions & 9 deletions syntax/ag.vim

This file was deleted.

8 changes: 8 additions & 0 deletions syntax/rg.vim
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ce47a04

Please sign in to comment.