mirror of
https://github.com/jremmen/vim-ripgrep.git
synced 2025-12-28 04:35:03 +08:00
Compare commits
No commits in common. "master" and "v1.0.0" have entirely different histories.
2 changed files with 11 additions and 45 deletions
17
README.md
17
README.md
|
|
@ -7,15 +7,14 @@ 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,31 +20,10 @@ 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>")
|
||||||
|
|
@ -54,16 +33,9 @@ fun! s:RgSearchTerm(txt)
|
||||||
endfun
|
endfun
|
||||||
|
|
||||||
fun! s:RgSearch(txt)
|
fun! s:RgSearch(txt)
|
||||||
let l:rgopts = ' '
|
silent! exe 'grep! ' . a:txt
|
||||||
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())
|
||||||
exe g:rg_window_location 'copen'
|
copen
|
||||||
redraw!
|
redraw!
|
||||||
if exists('g:rg_highlight')
|
if exists('g:rg_highlight')
|
||||||
call s:RgHighlight(a:txt)
|
call s:RgHighlight(a:txt)
|
||||||
|
|
@ -82,12 +54,8 @@ 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)
|
||||||
|
|
@ -95,7 +63,6 @@ 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
|
||||||
|
|
@ -146,4 +113,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! RgRoot :call s:RgShowRoot()
|
command! -complete=file RgRoot :call s:RgShowRoot()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue