I am a beginner with VIMscript. While coding, I need to update the tags and cscope database so I can jump and search newly added code (functions, macros etc.)
My .vimrc
file has following code:
function UpdateTags()
silent! execute (":!rm -rf tags cscope.files cscope.out")
silent! execute (":!ctags -R . *.c *.h *.hpp *.cpp --tag-relative=yes ./ 2>/dev/null")
silent! execute (":!cscope -b -R") | redraw!
normal == :cs reset<CR><CR>
normal == :TlistUpdate<CR>
endfunction
nnoremap <silent> <C-k> :call UpdateTags()<CR>
I see that the tags and cscope.out file is updated. However, i am unable to resolve these few things:
:TlistUpdate
command again manually, then I see the new tags.Following code is working:
function UpdateTags()
call system ("rm -rf tags cscope.files cscope.out")
call system ("ctags -R . *.c *.h *.hpp *.cpp --tag-relative=yes ./ 2>/dev/null")
call system ("cscope -b -R")
silent cscope reset
TlistUpdate
endfunction
sytem()
Swap execute
with system
. This has two benefits:
system
workssilent
instead of silent!
—the latter hides any errorsnormal ==
how you pretend the user ran ==
from normal mode. (You can avoid maps using normal!
.)
To run, e.g., :cscope reset
or :TlistUpdate
, you just run them:
function! UpdateTags() abort
" ...
cscope reset
TlistUpdate
" ...
endfunction