Vim 标记列表不会动态更新

Vim 标记列表不会动态更新,vim,ctags,cscope,Vim,Ctags,Cscope,我是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>/de

我是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>
system()
使用
系统
交换
执行
。这有两个好处:

  • 由于
    system
    的工作方式,屏幕不会闪烁,需要重新绘制
  • 您应该能够使用
    silent
    而不是
    silent-后者隐藏任何错误
  • 使用Ex(冒号)命令作为命令
    normal==
    如何假装用户从正常模式运行。(可以使用
    normal!
    避免贴图)

    要运行,例如,
    :cscope reset
    :TlistUpdate
    ,只需运行它们:

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

    normal==:命令
    在做什么?我一眼就明白了这一点。我按照这个链接在函数中添加了普通命令:这是专门用于重新缩进的。对于冒号/Ex命令,您不需要使用normal
    function! UpdateTags() abort
      " ...
      cscope reset
      TlistUpdate
      " ...
    endfunction