【问题标题】:How to refresh taglist in vim?如何在vim中刷新标签列表?
【发布时间】:2011-01-02 10:38:19
【问题描述】:

当我对文件进行更改时,例如添加一个函数,如何让 taglist 在我保存更改后自动更新其窗口中的“标签列表”?

【问题讨论】:

    标签: vim


    【解决方案1】:

    我根据C++ code completion vim tip 调整了我的设置。

    map <C-F12> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>
    

    在需要时,我按 Ctrl-F12 重新生成标签。

    如果您使用vim-taglist,您可以在.vimrc 中添加autocommand 以在每次保存后更新标记列表窗口:

    autocmd BufWritePost *.cpp :TlistUpdate
    

    【讨论】:

      【解决方案2】:

      尚未测试,但您可以尝试以下方法:

      au BufWritePre     *.cpp ks|!ctags %
      

      当以.cpp 结尾的文件的缓冲区被保存(:w)时,它基本上会执行 ctags。

      【讨论】:

        【解决方案3】:

        我确实写了一个little experimental script,它会自动增量更新文件保存时的“当前”标签文件。

        (这个问题实际上与Vim auto-generate ctags是多余的)

        【讨论】:

          【解决方案4】:

          http://vim.wikia.com/wiki/Autocmd_to_update_ctags_file

          只需将其添加到您的 ~/.vimrc

          function! DelTagOfFile(file)
            let fullpath = a:file
            let cwd = getcwd()
            let tagfilename = cwd . "/tags"
            let f = substitute(fullpath, cwd . "/", "", "")
            let f = escape(f, './')
            let cmd = 'sed -i "/' . f . '/d" "' . tagfilename . '"'
            let resp = system(cmd)
          endfunction
          
          function! UpdateTags()
            let f = expand("%:p")
            let cwd = getcwd()
            let tagfilename = cwd . "/tags"
            let cmd = 'ctags -a -f ' . tagfilename . ' --c++-kinds=+p --fields=+iaS --extra=+q ' . '"' . f . '"'
            call DelTagOfFile(f)
            let resp = system(cmd)
          endfunction
          autocmd BufWritePost *.cpp,*.h,*.c call UpdateTags()
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2016-07-24
            • 2010-11-12
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多