ctags自动更新omnicppcomplete的tags自动设定

度娘找不到这方面的东西,自己看了一下,写出来方便大家可以快速的解决问题。

1,获取tags的路径

  • 通常一个开发环境下会有多个源码库,需要vim根据环境进行自动识别。
  • "define by self                                                                                                                                       
    let zselfCtagsPath = 0                                                                                                                                
    function! GetCtagsPath()                                                                                                                              
        let getdir = getcwd()                                                                                                                             
        while !isdirectory(getdir . "/.git")                                                                                                              
            if isdirectory(getdir . "/home")                                                                                                              
                break                                                                                                                                     
            endif                                                                                                                                         
            let getdir = getdir . '/..'                                                                                                                   
        endwhile                                                                                                                                          
                                                                                                                                                          
        "getdir is root path or git path                                                                                                                  
        if isdirectory(getdir . "/.git")                                                                                                                  
            if filereadable(getdir . "/aclocal.m4")                                                                                                       
                "kingbase or pg code                                                                                                                      
                let getdir = getdir . '/src'                                                                                                              
            endif                                                                                                                                         
        else                                                                                                                                              
            "not found git used current path                                                                                                              
            let getdir = getcwd()                                                                                                                         
        endif                                                                                                                                             
        let g:zselfCtagsPath = getdir                                                                                                                     
    endfunction                                                                                                                                           
    call GetCtagsPath()     

2,ctags的更新

function! UpdateCtags()                                                                                                                               
    if filereadable(g:zselfCtagsPath . "/update_ctages.lock")                                                                                         
        echo "ctags is running"                                                                                                                       
        return                                                                                                                                        
    endif                                                                                                                                             
    "silent exe                                                                                                                                       
    "exe "!cd " . g:zselfCtagsPath . ";touch update_ctages.lock; (ctags --sort=foldcase -R --c++-kinds=+p --fields=+iaS --extra=+q . >/dev/null 2>&1; /bin/rm -f update_ctages.lock) &"
    exe "!cd " . g:zselfCtagsPath . ";touch update_ctages.lock; ctags --sort=foldcase -R --c++-kinds=+p --fields=+iaS --extra=+q . >/dev/null 2>&1; find . -name '*.[cyhl]' > cscope.file; cscope -c -b -i cscope.file >/dev/null 2>&1; /bin/rm -f update_ctages.lock "
endfunction
map <leader>uc :call UpdateCtags() <CR>

可以选择后台更新,PostgreSQL用时20几秒,我就选择了前台,比较直观

3,set tags的设定

let zselfOldTags = &tags                                                                                                                                    

let &tags = g:zselfOldTags . "," . g:zselfCtagsPath . "/tags"



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值