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:
- The screen flickers twice (I have put redraw only once in the function)
- The taglist does not get updated. If I execute
:TlistUpdatecommand 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
executewithsystem. This has two benefits:systemworkssilentinstead ofsilent!—the latter hides any errorsUse Ex (colon) commands as commands
normal ==how you pretend the user ran==from normal mode. (You can avoid maps usingnormal!.)To run, e.g.,
:cscope resetor:TlistUpdate, you just run them: