Taglist 不会动态更新

Taglist does not get updated dynamically

我是 VIMscript 的初学者。在编码时,我需要更新标签和 cscope 数据库,以便我可以跳转和搜索新添加的代码(函数、宏等)

我的 .vimrc 文件有以下代码:

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>

我看到标签和 cscope.out 文件已更新。但是,我无法解决以下几件事:

以下代码有效:

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()

execute 替换为 system。这有两个好处:

  1. 由于system 的工作原理
  2. ,屏幕不会闪烁并且需要重新绘制
  3. 您应该可以使用 silent 而不是 silent!——后者会隐藏任何错误

使用 Ex(冒号)命令作为命令

normal == 你如何假装用户 运行 == 来自正常模式。 (您可以使用 normal! 避免使用地图。)

至 运行,例如 :cscope reset:TlistUpdate,您只需 运行 他们:

function! UpdateTags() abort
  " ...
  cscope reset
  TlistUpdate
  " ...
endfunction