diff --git a/README.md b/README.md index 915183c..bbcd646 100644 --- a/README.md +++ b/README.md @@ -7,14 +7,15 @@ 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 +| 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 ## misc diff --git a/plugin/vim-ripgrep.vim b/plugin/vim-ripgrep.vim index 7e12922..7188001 100644 --- a/plugin/vim-ripgrep.vim +++ b/plugin/vim-ripgrep.vim @@ -20,10 +20,31 @@ if !exists('g:rg_root_types') let g:rg_root_types = ['.git'] 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) call s:RgGrepContext(function('s:RgSearch'), s:RgSearchTerm(a:txt)) 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) if empty(a:txt) return expand("") @@ -33,9 +54,16 @@ fun! s:RgSearchTerm(txt) endfun 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()) - copen + exe g:rg_window_location 'copen' redraw! if exists('g:rg_highlight') call s:RgHighlight(a:txt) @@ -54,8 +82,12 @@ fun! s:RgGrepContext(search, txt) let &grepformat = g:rg_format let l:te = &t_te let l:ti = &t_ti + let l:shellpipe_bak=&shellpipe set t_te= set t_ti= + if !has("win32") + let &shellpipe="&>" + endif if exists('g:rg_derive_root') call s:RgPathContext(a:search, a:txt) @@ -63,6 +95,7 @@ fun! s:RgGrepContext(search, txt) call a:search(a:txt) endif + let &shellpipe=l:shellpipe_bak let &t_te=l:te let &t_ti=l:ti let &grepprg = l:grepprgb @@ -113,4 +146,4 @@ fun! s:RgShowRoot() endfun command! -nargs=* -complete=file Rg :call s:Rg() -command! -complete=file RgRoot :call s:RgShowRoot() +command! RgRoot :call s:RgShowRoot()