It’s just yulistic!

Autoload Cscope Database

· by Jongyul Kim · Read in about 1 min · (141 Words)
cscope autoload srcexpl


Vim could not find the cscope db file (cscope.out) from any subdirectories of the project root. Although I could use cscope by accessing all the files from the project root directory, some plugins (SrcExpl) set autochdir option to be on automatically. Once the option was turned on, I could not use cscope any more with the error message like ‘Cannot find file.’


As mentioned in the reference site, the problem could be solved by adding the following script to the ~/.vimrc file which is the usual vim configuration file.

# ~/.vimrc file.
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
au BufEnter /* call LoadCscope()