History of Vim Tricks

Version 9

Vim Tricks

How to use cscope, vim and PHP for coding utopia.

Created by: xing, Last modification: 04 Jun 2008 (19:02 UTC) by xing
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


  1. Install cscope (via rpm, etc)
  2. Add this file to /usr/local/bin/cscope-php

    /usr/local/bin/cscope-php

    
    #!/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
  3. Have a periodic crontab like:

    cronjob

    
    0 * * * * /usr/local/bin/cscope-php /path/to/project1 /other/path/to/project2
  4. mkdir -p ~/.vim/plugin/ && curl -o ~/.vim/plugin/cscope_maps.vim http://cscope.sourceforge.net/cscope_maps.vim
  5. 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
Page History
Date/CommentUserIPVersion
25 Jul 2008 (18:26 UTC)
xing62.47.234.23123
Current • Source
xing62.47.234.23122
View • Compare • Difference • Source
xing62.47.234.23121
View • Compare • Difference • Source
xing62.47.234.23120
View • Compare • Difference • Source
spiderr76.182.96.2218
View • Compare • Difference • Source
xing62.47.237.12614
View • Compare • Difference • Source
xing62.47.233.18513
View • Compare • Difference • Source
spiderr76.182.96.2212
View • Compare • Difference • Source
xing62.47.233.18511
View • Compare • Difference • Source
spiderr76.182.96.2210
View • Compare • Difference • Source
xing62.47.233.1859
View • Compare • Difference • Source
xing62.47.233.1858
View • Compare • Difference • Source
spiderr76.182.96.227
View • Compare • Difference • Source