Speed up vim global search & replace and regen ctags after running

This commit is contained in:
Michael Campagnaro 2021-12-01 13:59:03 -05:00
parent 4dd5ea783c
commit 90df6cd8fb

27
vimrc
View File

@ -676,15 +676,15 @@ function! s:CompleteFilenameWithoutExtension(ArgLead, CmdLine, CursorPos)
endfunction
" Custom command to open cpp and h files without typing an extension
"command! -nargs=+ -complete=custom,s:CompleteFilenameWithoutExtension OpenCppSource execute ':e <args>.cpp'
"command! -nargs=+ -complete=custom,s:CompleteFilenameWithoutExtension "OpenCppSource exec ':e <args>.cpp'
":ca c OpenCppSource
":ca C OpenCppSource
"command! -nargs=+ -complete=custom,s:CompleteFilenameWithoutExtension OpenCppHeader execute ':e <args>.h'
"command! -nargs=+ -complete=custom,s:CompleteFilenameWithoutExtension "OpenCppHeader exec ':e <args>.h'
":ca h OpenCppHeader
":ca H OpenCppHeader
"command! -nargs=+ -complete=custom,s:CompleteFilenameWithoutExtension OpenCppSourceAndHeader execute ':vsp | :e <args>.h | :sp <args>.cpp'
"command! -nargs=+ -complete=custom,s:CompleteFilenameWithoutExtension "OpenCppSourceAndHeader exec ':vsp | :e <args>.h | :sp <args>.cpp'
":ca b OpenCppSourceAndHeader
":ca B OpenCppSourceAndHeader
@ -929,8 +929,8 @@ set statusline=%<%f\ (%{&ft})\ %-4(%m%)%=%-19(%3l,%02c%03V%)
" COLORS
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
execute "autocmd ColorScheme " . g:campo_dark_theme . " call ReloadRainbow()"
execute "autocmd ColorScheme " . g:campo_light_theme . " call ReloadRainbow()"
exec "autocmd ColorScheme " . g:campo_dark_theme . " call ReloadRainbow()"
exec "autocmd ColorScheme " . g:campo_light_theme . " call ReloadRainbow()"
" Switch between light and dark themes.
map <leader>l :call ChangeBgTheme('light', 0)<cr>
@ -1020,7 +1020,7 @@ augroup END
"################################################################
function! PrintError(msg) abort
execute 'normal! \<Esc>'
exec 'normal! \<Esc>'
echohl ErrorMsg
echomsg a:msg
echohl None
@ -1149,6 +1149,15 @@ nnoremap <expr> p (&buftype is# "quickfix" ? "<CR>\|:copen<CR>" : "p")
" SEARCH & REPLACE
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" argdo wrapper that will disable all events for read/save. This significantly
" speeds up GlobalReplaceIt().
command! -nargs=? Argdo call Argdo(<q-args>)
function! Argdo(command)
set eventignore=all
exec 'noautocmd argdo '. a:command . ' | update'
set eventignore=
endfunction
" Replace the selected text in all files within the repo.
function! GlobalReplaceIt(confirm_replacement)
if exists(':Ggrep')
@ -1178,8 +1187,10 @@ function! GlobalReplaceIt(confirm_replacement)
let l:confirm_opt = 'e'
endif
execute 'Ggrep '.l:term
execute 'Qargs | argdo %s/'.l:term.'/'.l:replacement.'/g'.l:confirm_opt
exec 'Ggrep '.l:term
exec 'Qargs | Argdo %s/'.l:term.'/'.l:replacement.'/g'.l:confirm_opt
" Regen ctags.
call s:RunCtags()
else
PrintError "Unable to search since you're not in a git repo!"
endif