@@ -28,6 +28,10 @@ if !exists('g:rg_window_location')
2828 let g: rg_window_location = ' botright'
2929endif
3030
31+ if ! exists (' g:rg_use_location_list' )
32+ let g: rg_use_location_list = 0
33+ endif
34+
3135fun ! g: RgVisual () range
3236 call s: RgGrepContext (function (' s:RgSearch' ), ' "' . s: RgGetVisualSelection () . ' "' )
3337endfun
@@ -36,6 +40,13 @@ fun! s:Rg(txt)
3640 call s: RgGrepContext (function (' s:RgSearch' ), s: RgSearchTerm (a: txt ))
3741endfun
3842
43+ fun ! s: LRg (txt)
44+ let l: rg_use_location_list_bak = g: rg_use_location_list
45+ let g: rg_use_location_list = 1
46+ call s: RgGrepContext (function (' s:RgSearch' ), s: RgSearchTerm (a: txt ))
47+ let g: rg_use_location_list = l: rg_use_location_list_bak
48+ endfun
49+
3950fun ! s: RgGetVisualSelection ()
4051 " Why is this not a built-in Vim script function?!
4152 let [line_start, column_start] = getpos (" '<" )[1 :2 ]
@@ -65,15 +76,24 @@ fun! s:RgSearch(txt)
6576 if &smartcase == 1
6677 let l: rgopts = l: rgopts . ' -S '
6778 endif
68- silent ! exe ' grep! ' . l: rgopts . a: txt
69- if len (getqflist ())
70- exe g: rg_window_location ' copen'
79+ if (g: rg_use_location_list== 1 )
80+ let l: rg_grep_cmd = ' lgrep! '
81+ let l: rg_window_cmd = ' lopen'
82+ let l: rg_window_close_cmd = ' lclose'
83+ else
84+ let l: rg_grep_cmd = ' grep! '
85+ let l: rg_window_cmd = ' copen'
86+ let l: rg_window_close_cmd = ' cclose'
87+ endif
88+ silent ! exe l: rg_grep_cmd . l: rgopts . a: txt
89+ if (g: rg_use_location_list ? len (getloclist (0 )) : len (getqflist ()))
90+ exe g: rg_window_location . ' ' . l: rg_window_cmd
7191 redraw !
7292 if exists (' g:rg_highlight' )
7393 call s: RgHighlight (a: txt )
7494 endif
7595 else
76- cclose
96+ exe l: rg_window_close_cmd
7797 redraw !
7898 echo " No match found for " . a: txt
7999 endif
@@ -161,4 +181,5 @@ fun! s:RgGetCwd() abort
161181endfun
162182
163183command ! -nargs =* -complete =file Rg :call s: Rg (<q-args> )
184+ command ! -nargs =* -complete =file LRg :call s: LRg (<q-args> )
164185command ! -complete =file RgRoot :call s: RgShowRoot ()
0 commit comments