Exit vim search functions when not given input

This commit is contained in:
Michael Campagnaro 2019-04-02 13:40:52 -04:00
parent e60401402c
commit cbf3d73649

19
vimrc
View File

@ -932,22 +932,26 @@ map <leader>gs :let @/ = ""<CR>
" Replace the selected text in all files within the repo " Replace the selected text in all files within the repo
function! GlobalReplaceIt(confirm_replacement) function! GlobalReplaceIt(confirm_replacement)
if exists(':Ggrep') if exists(':Ggrep')
" let term = @/
" if empty(term)
call inputsave() call inputsave()
let l:term = input('Enter search term: ') let l:term = input('Enter search term: ')
call inputrestore() call inputrestore()
" else if empty(l:term)
" echo '\nReplacing '.term return
" endif endif
call inputsave() call inputsave()
let l:replacement = input('Enter replacement: ') let l:replacement = input('Enter replacement: ')
call inputrestore() call inputrestore()
if empty(l:replacement)
return
endif
if a:confirm_replacement if a:confirm_replacement
let l:confirm_opt = 'c' let l:confirm_opt = 'c'
else else
let l:confirm_opt = 'e' let l:confirm_opt = 'e'
endif endif
execute 'Ggrep '.l:term execute 'Ggrep '.l:term
execute 'Qargs | argdo %s/'.l:term.'/'.l:replacement.'/g'.l:confirm_opt.' | update' execute 'Qargs | argdo %s/'.l:term.'/'.l:replacement.'/g'.l:confirm_opt.' | update'
else else
@ -959,7 +963,9 @@ map <leader>gr :call GlobalReplaceIt(1)<cr>
function! Search() function! Search()
let l:term = input('Grep search term: ') let l:term = input('Grep search term: ')
if l:term != '' if empty(l:term)
return
endif
if IsWindows() if IsWindows()
"Fsgrep is slow...." "Fsgrep is slow...."
"exec 'Fsgrep "' . l:term . '"' "exec 'Fsgrep "' . l:term . '"'
@ -972,7 +978,6 @@ function! Search()
" ripgrep is faster than Ag. " ripgrep is faster than Ag.
execute 'Find '.l:term execute 'Find '.l:term
endif endif
endif
endfunction endfunction
map <leader>s :call Search()<cr> map <leader>s :call Search()<cr>