From 7d01d6976b1932e289d82cd1ee063313adea5a7b Mon Sep 17 00:00:00 2001 From: = Date: Tue, 20 Mar 2018 23:43:12 -0700 Subject: [PATCH 1/2] Add function for searching a visual selection --- plugin/vim-ripgrep.vim | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/plugin/vim-ripgrep.vim b/plugin/vim-ripgrep.vim index 3069eb2..0a1cd16 100644 --- a/plugin/vim-ripgrep.vim +++ b/plugin/vim-ripgrep.vim @@ -24,10 +24,27 @@ 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("") @@ -37,7 +54,7 @@ fun! s:RgSearchTerm(txt) endfun fun! s:RgSearch(txt) - silent! exe 'grep! ' . a:txt + silent! exe 'grep! ' . '"' . a:txt . '"' if len(getqflist()) exe g:rg_window_location 'copen' redraw! From 0df3ac2c3e51d27637251a5849f892c3a0f0bce0 Mon Sep 17 00:00:00 2001 From: = Date: Tue, 20 Mar 2018 23:53:34 -0700 Subject: [PATCH 2/2] Respect vim's smartcase and ignorecase options. Resolve's https://github.com/jremmen/vim-ripgrep/issues/5 --- plugin/vim-ripgrep.vim | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/plugin/vim-ripgrep.vim b/plugin/vim-ripgrep.vim index 0a1cd16..ba41aa8 100644 --- a/plugin/vim-ripgrep.vim +++ b/plugin/vim-ripgrep.vim @@ -54,7 +54,14 @@ 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()) exe g:rg_window_location 'copen' redraw!