Ad blocker interference detected!
Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers
Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.
created February 11, 2011 · complexity basic · author Dorserg · version 7.0
By default, Cscope script adds
cscope.out from Vim's current directory and from
$CSCOPE_DB. However, if you start Vim from say
cscope.out is at
cscope.out won't be loaded automatically.
For ctags, there is a nice trick: with the command
:set tags=tags;/ Vim will look for tags file everywhere starting from the current directory up to the root.
This tip provides the same "autoloading" functionality for Cscope. Just add the following to your vimrc:
function! LoadCscope() 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 endfunction au BufEnter /* call LoadCscope()
If somebody use gVim in the windows(like me use Winxp), a modified script for the _vimrc script maybe helpful as follow:
function LoadCscope() 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 endfunction command LoadCscope call LoadCscope()
The last statement "Command LoadCscope call LoadCscope()" means that we can use command :LoadCscope to call the function LoadCscope for convinence.