From 125880e6659a3f4c693adbaa2ae551c343810c73 Mon Sep 17 00:00:00 2001 From: Michael Campagnaro Date: Sat, 27 Apr 2019 11:42:58 -0400 Subject: [PATCH] Refactor search fn in vimrc --- vimrc | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/vimrc b/vimrc index 29a9d42..61ab077 100644 --- a/vimrc +++ b/vimrc @@ -341,7 +341,7 @@ augroup campoCmds " Generate ctags " Include local variables for c languages. - au BufWritePost *.py,*.c,*.cpp,*.h silent! !eval 'ctags --c-types=+l --c++-types=+l -R -o newtags; mv newtags tags' & + au BufWritePost *.py,*.c,*.cpp,*.h silent! !eval 'ctags --c-types=+l --c++-types=+l --exclude=vendor -R -o newtags; mv newtags tags' & " Remove trailing whitespace on save all files. function! StripTrailingWhitespaces() @@ -477,7 +477,7 @@ map v :e %:p:s,.h$,.X123X,:s,.cpp$,.h,:s,.X123X$,.cpp, "map vvv :e %:p:s,.h$,.X123X,:s,.cc$,.h,:s,.X123X$,.cc, " Replace all instances of the highlighted text with whatever you enter. -nnoremap :%s///g +nnoremap :%s///g "//////////////////////////////////////////////////////////////// " QUICKLY OPEN C++ SOURCE OR HEADER FILE @@ -961,25 +961,34 @@ endfunction map gg :call GlobalReplaceIt(0) map gr :call GlobalReplaceIt(1) -function! Search() - let l:term = input('Grep search term: ') - if empty(l:term) +function! Search(case_insensitive) + let helper = "[" . (a:case_insensitive ? "case-insensitive" : "case-sensitive") . "] search: " + let term = input(helper) + if empty(term) return endif - if IsWindows() - "Fsgrep is slow...." - "exec 'Fsgrep "' . l:term . '"' - "@note --pretty (i.e. colors) is not enabled in vim-ripgrep because the - "quickfix window doesn't seem to parse the ansi color codes. - exec 'Rg --trim --ignore-case -g "!vendor/*" "' . l:term . '"' + "@note --pretty (i.e. colors) is not enabled in vim-ripgrep because the + "quickfix window doesn't seem to parse the ansi color codes. + let rg_args = "--trim -g \"!vendor/*\"" + + if a:case_insensitive + let rg_args .= " --ignore-case" + endif + + if IsWindows() + "@deprecated: Fsgrep is slow...." + "exec 'Fsgrep "' . term . '"' + exec 'Rg ' . rg_args . ' "' . term . '"' else - "exec 'Ag "' . l:term . '"' - " ripgrep is faster than Ag. - execute 'Find '.l:term + "@deprecated: ripgrep is faster than Ag. + "exec 'Ag "' . term . '"' + " @incomplete pass case sensitivity toggle to Find. + execute 'Find ' . term endif endfunction -map s :call Search() +map s :call Search(1) +map ss :call Search(0) " Navigation for the vim-ripgrep search results. " Hit o on a result line to open the file at that line.