Skip to content

Commit

Permalink
Use vim's syntax highlighting for the result highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
svranesevic committed Sep 14, 2023
1 parent ac35dd1 commit 61a2d15
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
29 changes: 17 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
# vim-ripgrep

:Rg <string|pattern>
```vim
:Rg <string|pattern>
```

Word under cursor will be searched if no argument is passed to `Rg`

## configuration


| Setting | Default | Details
| ---------------------|---------------------------|----------
| g:rg_binary | rg | path to rg
| g:rg_format | %f:%l:%c:%m | value of grepformat
| g:rg_command | g:rg_binary --vimgrep | search command
| g:rg_highlight | false | true if you want matches highlighted
| g:rg_derive_root | false | true if you want to find project root from cwd
| g:rg_root_types | ['.git'] | list of files/dir found in project root
| g:rg_window_location | botright | quickfix window location

| Setting | Default | Details
| ----------------------|---------------------------|----------
| g:rg_binary | rg | path to rg
| g:rg_format | %f:%l:%c:%m | value of grepformat
| g:rg_command | g:rg_binary --vimgrep | search command
| g:rg_highlight | false | true if you want matches highlighted
| g:rg_highlight_type | `identifier` | if `rg_highlight` is set, use this syntax color to highlight the result
| g:rg_derive_root | false | true if you want to find project root from cwd
| g:rg_root_types | ['.git'] | list of files/dir found in project root
| g:rg_window_location | botright | quickfix window location

## misc

Show root search dir

:RgRoot
```vim
:RgRoot
```
7 changes: 5 additions & 2 deletions plugin/vim-ripgrep.vim
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ if !exists('g:rg_window_location')
let g:rg_window_location = 'botright'
endif

if !exists('g:rg_highlight_type')
let g:rg_highlight_type = 'keyword'
endif

fun! g:RgVisual() range
call s:RgGrepContext(function('s:RgSearch'), '"' . s:RgGetVisualSelection() . '"')
endfun
Expand Down Expand Up @@ -111,8 +115,7 @@ fun! s:RgPathContext(search, txt)
endfun

fun! s:RgHighlight(txt)
let @/=escape(substitute(a:txt, '"', '', 'g'), '|')
call feedkeys(":let &hlsearch=1\<CR>", 'n')
call matchadd(g:rg_highlight_type, a:txt)
endfun

fun! s:RgRootDir()
Expand Down

0 comments on commit 61a2d15

Please sign in to comment.