vim: 自动更新ctags

来源:互联网 发布:程序员接项目的网站 编辑:程序博客网 时间:2024/05/17 08:21


"ctags自动更新

"windows
function! UPDATE_TAGS()
  let _f_ = expand("%:p")
  let _cmd_ = '"ctags -R --c++-kinds=+p--fields=+iaS --extra=+q ."'
  let _resp = system(_cmd_)
  unlet _cmd_
  unlet _f_
  unlet _resp
endfunction
autocmd BufWrite *.cpp,*.h,*.c call UPDATE_TAGS()


"linux
function! DelTagOfFile(file)
 86        let fullpath = a:file
 87        let cwd = getcwd()
 88        let tagfilename = cwd ."/tags"
 89        let f = substitute(fullpath,cwd . "/", "", "")
 90        let f = escape(f, './')
 91        let cmd = 'sed -i "/' . f .'/d" "' . tagfilename . '"'
 92        let resp = system(cmd)
 93 endfunction
 94 
 95 function! AutoTags()
 96        let f = expand("%:p")
 97        let cwd = getcwd()
 98        let tagfilename = cwd ."/tags"
 99        let cmd = 'ctags -a -f ' .tagfilename . ' --c++-kinds=+p --fields=+   iaS --extra=+q ' . '"' . f . '"'
100        call DelTagOfFile(f)
101        let resp = system(cmd)
102 endfunction
103 autocmd BufWritePost *.cpp,*.h,*.c call AutoTags()


window方法会更新整个目录,速度比较慢, linux版本反映要快很多,但全目录查找时有些问题,easyvim插件对与很多源文件反应速度最慢, 所以最好的方式是: 采用linux方式自动更新,必要时手动更新全目录tag
                                            


0 0