Taglist does not get updated dynamically

161 Views Asked by At

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 :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
1

There are 1 best solutions below

0
D. Ben Knoble On BEST ANSWER

sytem()

Swap execute with system. This has two benefits:

  1. The screen doesn't blink and need redrawing, because of how system works
  2. You should be able to use silent instead of silent!—the latter hides any errors

Use Ex (colon) commands as commands

normal == 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