您的位置:首页 > 运维架构

vim自动加载cscope.out

2013-10-28 00:06 393 查看
cscope可以查找代码的引用、定义等,但是当用vim直接打开项目子目录中的一个文件时,cscope.out不能直接加载。在网上搜了一把,autoload_cscope插件可以解决这个问题,但是这个插件只针对c, h文件,打开cpp时好像不能生效(可能是我没找到设置的地方)。在vim官网上搜了一把,找到了解决方法。看来凡事还是要先官网看下啊,省的耽搁时间。

话不多说,直接代码。

打开文件后,F12就可以自动加入cscope.out了。

map <F12> :call LoadCscope()<CR>
function! LoadCscope()
if (g:iswindows==1)
if (executable("cscope") && has("cscope"))
let UpperPath = findfile("cscope.out", ".;")
if (!empty(UpperPath))
let path = strpart(UpperPath, 0, match(UpperPath, "cscope.out$") - 1)
if (!empty(path))
let s:CurrentDir = getcwd()
let direct = strpart(s:CurrentDir, 0, 2)
let s:FullPath = direct . path
let s:AFullPath = globpath(s:FullPath, "cscope.out")
let s:CscopeAddString = "cs add " . s:AFullPath . " " . s:FullPath
execute s:CscopeAddString
endif
endif
endif
else
let db = findfile("cscope.out", ".;")
if (!empty(db))
let path = strpart(db, 0, match(db, "/cscope.out$"))
set nocscopeverbose " suppress 'duplicate connection' error
exe "cs add " . db . " " . path
set cscopeverbose
endif
endif
endfunction


Reference:

https://vim.wikia.com/wiki/Autoloading_Cscope_Database
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: