度娘找不到这方面的东西,自己看了一下,写出来方便大家可以快速的解决问题。
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"