From 318b058c00a24db4cd5f280eb086823f5cd14e11 Mon Sep 17 00:00:00 2001 From: Cosson2017 Date: Wed, 21 Nov 2018 11:22:21 +0800 Subject: [PATCH 1/2] support local list --- plugin/vim-ripgrep.vim | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/plugin/vim-ripgrep.vim b/plugin/vim-ripgrep.vim index 9bc029d..3c5c462 100644 --- a/plugin/vim-ripgrep.vim +++ b/plugin/vim-ripgrep.vim @@ -24,6 +24,24 @@ if !exists('g:rg_window_location') let g:rg_window_location = 'botright' endif +if !exists('g:rg_use_local_list') + let g:rg_use_local_list = 0 +endif + +let s:rg_window_cmd = 'copen' +let s:rg_grep_cmd = 'grep! ' +if g:rg_use_local_list != 0 + let s:rg_window_cmd = 'lopen' + let s:rg_grep_cmd = 'lgrep! ' +end + +fun! s:get_match_len() + if g:rg_use_local_list != 0 + return len(getloclist(0)) + end + return len(getqflist()) +endfun + fun! g:RgVisual() range call s:RgGrepContext(function('s:RgSearch'), '"' . s:RgGetVisualSelection() . '"') endfun @@ -61,9 +79,9 @@ fun! s:RgSearch(txt) if &smartcase == 1 let l:rgopts = l:rgopts . '-S ' endif - silent! exe 'grep! ' . l:rgopts . a:txt - if len(getqflist()) - exe g:rg_window_location 'copen' + silent! exe s:rg_grep_cmd . l:rgopts . a:txt + if s:get_match_len() + exe g:rg_window_location s:rg_window_cmd redraw! if exists('g:rg_highlight') call s:RgHighlight(a:txt) From 66f43d1f849c2238b7d1dbd20d01c3d8c467e286 Mon Sep 17 00:00:00 2001 From: Cosson2017 Date: Wed, 21 Nov 2018 13:26:56 +0800 Subject: [PATCH 2/2] readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index bbcd646..411e9aa 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ Word under cursor will be searched if no argument is passed to `Rg` | 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 +| g:rg_use_local_list | 0 | use local list instead of quickfix for search ## misc