mirror of
https://github.com/jremmen/vim-ripgrep.git
synced 2025-12-27 04:04:58 +08:00
Compare commits
13 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2bb2425387 | ||
|
|
84d148676e | ||
|
|
ec87af6b69 | ||
|
|
8d27cd24cd | ||
|
|
f7c1549c0b | ||
|
|
63df8132f5 | ||
|
|
d112b6127f | ||
|
|
552232da7c | ||
|
|
0df3ac2c3e | ||
|
|
7d01d6976b | ||
|
|
88ce3691b6 | ||
|
|
6e2fdfe189 | ||
|
|
1e9f916d34 |
2 changed files with 45 additions and 11 deletions
17
README.md
17
README.md
|
|
@ -7,14 +7,15 @@ Word under cursor will be searched if no argument is passed to `Rg`
|
||||||
## configuration
|
## configuration
|
||||||
|
|
||||||
|
|
||||||
| Setting | Default | Details
|
| Setting | Default | Details
|
||||||
| -----------------|---------------------------|----------
|
| ---------------------|---------------------------|----------
|
||||||
| g:rg_binary | rg | path to rg
|
| g:rg_binary | rg | path to rg
|
||||||
| g:rg_format | %f:%l:%c:%m | value of grepformat
|
| g:rg_format | %f:%l:%c:%m | value of grepformat
|
||||||
| g:rg_command | g:rg_binary --vimgrep | search command
|
| g:rg_command | g:rg_binary --vimgrep | search command
|
||||||
| g:rg_highlight | false | true if you want matches highlighted
|
| 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_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_root_types | ['.git'] | list of files/dir found in project root
|
||||||
|
| g:rg_window_location | botright | quickfix window location
|
||||||
|
|
||||||
## misc
|
## misc
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,10 +20,31 @@ if !exists('g:rg_root_types')
|
||||||
let g:rg_root_types = ['.git']
|
let g:rg_root_types = ['.git']
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
if !exists('g:rg_window_location')
|
||||||
|
let g:rg_window_location = 'botright'
|
||||||
|
endif
|
||||||
|
|
||||||
|
fun! g:RgVisual() range
|
||||||
|
call s:RgGrepContext(function('s:RgSearch'), '"' . s:RgGetVisualSelection() . '"')
|
||||||
|
endfun
|
||||||
|
|
||||||
fun! s:Rg(txt)
|
fun! s:Rg(txt)
|
||||||
call s:RgGrepContext(function('s:RgSearch'), s:RgSearchTerm(a:txt))
|
call s:RgGrepContext(function('s:RgSearch'), s:RgSearchTerm(a:txt))
|
||||||
endfun
|
endfun
|
||||||
|
|
||||||
|
fun! s:RgGetVisualSelection()
|
||||||
|
" Why is this not a built-in Vim script function?!
|
||||||
|
let [line_start, column_start] = getpos("'<")[1:2]
|
||||||
|
let [line_end, column_end] = getpos("'>")[1:2]
|
||||||
|
let lines = getline(line_start, line_end)
|
||||||
|
if len(lines) == 0
|
||||||
|
return ''
|
||||||
|
endif
|
||||||
|
let lines[-1] = lines[-1][: column_end - (&selection == 'inclusive' ? 1 : 2)]
|
||||||
|
let lines[0] = lines[0][column_start - 1:]
|
||||||
|
return join(lines, "\n")
|
||||||
|
endfun
|
||||||
|
|
||||||
fun! s:RgSearchTerm(txt)
|
fun! s:RgSearchTerm(txt)
|
||||||
if empty(a:txt)
|
if empty(a:txt)
|
||||||
return expand("<cword>")
|
return expand("<cword>")
|
||||||
|
|
@ -33,9 +54,16 @@ fun! s:RgSearchTerm(txt)
|
||||||
endfun
|
endfun
|
||||||
|
|
||||||
fun! s:RgSearch(txt)
|
fun! s:RgSearch(txt)
|
||||||
silent! exe 'grep! ' . a:txt
|
let l:rgopts = ' '
|
||||||
|
if &ignorecase == 1
|
||||||
|
let l:rgopts = l:rgopts . '-i '
|
||||||
|
endif
|
||||||
|
if &smartcase == 1
|
||||||
|
let l:rgopts = l:rgopts . '-S '
|
||||||
|
endif
|
||||||
|
silent! exe 'grep! ' . l:rgopts . a:txt
|
||||||
if len(getqflist())
|
if len(getqflist())
|
||||||
copen
|
exe g:rg_window_location 'copen'
|
||||||
redraw!
|
redraw!
|
||||||
if exists('g:rg_highlight')
|
if exists('g:rg_highlight')
|
||||||
call s:RgHighlight(a:txt)
|
call s:RgHighlight(a:txt)
|
||||||
|
|
@ -54,8 +82,12 @@ fun! s:RgGrepContext(search, txt)
|
||||||
let &grepformat = g:rg_format
|
let &grepformat = g:rg_format
|
||||||
let l:te = &t_te
|
let l:te = &t_te
|
||||||
let l:ti = &t_ti
|
let l:ti = &t_ti
|
||||||
|
let l:shellpipe_bak=&shellpipe
|
||||||
set t_te=
|
set t_te=
|
||||||
set t_ti=
|
set t_ti=
|
||||||
|
if !has("win32")
|
||||||
|
let &shellpipe="&>"
|
||||||
|
endif
|
||||||
|
|
||||||
if exists('g:rg_derive_root')
|
if exists('g:rg_derive_root')
|
||||||
call s:RgPathContext(a:search, a:txt)
|
call s:RgPathContext(a:search, a:txt)
|
||||||
|
|
@ -63,6 +95,7 @@ fun! s:RgGrepContext(search, txt)
|
||||||
call a:search(a:txt)
|
call a:search(a:txt)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
let &shellpipe=l:shellpipe_bak
|
||||||
let &t_te=l:te
|
let &t_te=l:te
|
||||||
let &t_ti=l:ti
|
let &t_ti=l:ti
|
||||||
let &grepprg = l:grepprgb
|
let &grepprg = l:grepprgb
|
||||||
|
|
@ -113,4 +146,4 @@ fun! s:RgShowRoot()
|
||||||
endfun
|
endfun
|
||||||
|
|
||||||
command! -nargs=* -complete=file Rg :call s:Rg(<q-args>)
|
command! -nargs=* -complete=file Rg :call s:Rg(<q-args>)
|
||||||
command! -complete=file RgRoot :call s:RgShowRoot()
|
command! RgRoot :call s:RgShowRoot()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue