Exit vim search functions when not given input
This commit is contained in:
parent
e60401402c
commit
cbf3d73649
45
vimrc
45
vimrc
|
@ -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 = @/
|
call inputsave()
|
||||||
" if empty(term)
|
let l:term = input('Enter search term: ')
|
||||||
call inputsave()
|
call inputrestore()
|
||||||
let l:term = input('Enter search term: ')
|
if empty(l:term)
|
||||||
call inputrestore()
|
return
|
||||||
" else
|
endif
|
||||||
" echo '\nReplacing '.term
|
|
||||||
" 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,19 +963,20 @@ 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)
|
||||||
if IsWindows()
|
return
|
||||||
"Fsgrep is slow...."
|
endif
|
||||||
"exec 'Fsgrep "' . l:term . '"'
|
if IsWindows()
|
||||||
|
"Fsgrep is slow...."
|
||||||
|
"exec 'Fsgrep "' . l:term . '"'
|
||||||
|
|
||||||
"@note --pretty (i.e. colors) is not enabled in vim-ripgrep because the
|
"@note --pretty (i.e. colors) is not enabled in vim-ripgrep because the
|
||||||
"quickfix window doesn't seem to parse the ansi color codes.
|
"quickfix window doesn't seem to parse the ansi color codes.
|
||||||
exec 'Rg --trim --ignore-case -g "!vendor/*" "' . l:term . '"'
|
exec 'Rg --trim --ignore-case -g "!vendor/*" "' . l:term . '"'
|
||||||
else
|
else
|
||||||
"exec 'Ag "' . l:term . '"'
|
"exec 'Ag "' . l:term . '"'
|
||||||
" 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>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user