History of Vim Tricks
Version 12
Vim Tricks
How to use cscope, vim and PHP for coding utopia.
vim + cscope is insanely cool.
What's cscope?
cscope will generate a list of functions used in bitweaver and you can use a few keymaps to very quickly jump to those functions from within bitweaver (or any source code tree). cscope is faster and more feature rich than ctags.Setting it up
- Install cscope (via rpm, etc)
- Add this file to /usr/local/bin/cscope-php-update and chmod 755 /usr/local/bin/cscope-php-update
/usr/local/bin/cscope-php-update
#!/bin/bash
for arg in "$@"; do
if [ -d $arg ]; then
#echo Create list of php files in cscope.files
find $arg \( -name "*.php" -or -name "*.tpl" \) -and -not -regex "./temp/.*" -and -not -regex ".*/language.php" -print > $arg/cscope.files
#echo Create cscope database in cscope.out
cscope -b -i $arg/cscope.files -f$arg/cscope.out
rm -f $arg/cscope.files
else
echo "Directory not found: $arg"
fi
done
- Have a periodic crontab like:
cronjob
0 * * * * /usr/local/bin/cscope-php /path/to/project1 /other/path/to/project2
- mkdir -p ~/.vim/plugin/ && curl -o ~/.vim/plugin/cscope_maps.vim http://cscope.sourceforge.net/cscope_maps.vim
- Remove duplicate add code from ~/.vim/plugin/cscope_maps.vim
" add any database in current directory
if filereadable("./cscope.out")
cs add ./cscope.out
" else add database pointed to by environment
elseif $CSCOPE_DB != ""
cs add $CSCOPE_DB
endif
- Add the following to your ~/.vimrc (or /etc/vimrc for cool people)
~/.vimrc or /etc/vimrc
" Some scsope specific settings
if has("cscope")
" Some scsope specific settings
set cscopequickfix=s-,c-,d-,i-,t-,e-
" always use cscope instead of tags
set cst
" path to cscope
set csprg=/usr/bin/cscope
" search databased before searching tag files
set cscopetagorder=0
" don\'t display cscope messages when adding database
set nocsverb
" add any database in current directory
if filereadable("cscope.out")
cs add cscope.out
" else search up a few directories
elseif filereadable("../cscope.out")
cs add ../cscope.out
elseif filereadable("../../cscope.out")
cs add ../../cscope.out
elseif filereadable("../../../cscope.out")
cs add ../../../cscope.out
elseif filereadable("../../../../cscope.out")
cs add ../../../../cscope.out
elseif filereadable("../../../../../cscope.out")
cs add ../../../../../cscope.out
" else add database pointed to by environment
elseif \$CSCOPE_DB != ""
cs add \$CSCOPE_DB
endif
" reset cscope verbosity
set csverb
" easily reload cscope database
nmap <F11> :cs reset<cr>
endif
- To test if this worked:
$ cd /path/to/bitweaver
$ vim wiki/index.php +/verifyPackage
move your cursor over verifyPackage
<CTRL-\>g will go to where the function was defined
<CTRL-\>s will show all places where the function has been used
use ':copen' to view the complete list.