Cscope tags with Vim: easy setup

These setup steps will help you to browse code efficiently

Steps :

Install Cscope, if you already have ignore this step

apt-get install cscope

Install cscope plugins

mkdir ~/.vim/plugins
cd ~/.vim/plugins
wget http://cscope.sourceforge.net/cscope_maps.vim

Add this below line in .vimrc file

source ~/.vim/plugins/cscope_maps.vim

In .bashrc file add these lines. This will create an alias which will search and index the file types as mentioned

alias mycscope='export SB=$PWD;find $SB ( -name '.[chs]' -o -name '.cc' -o -name '.cpp' -o -name '.hh' ) > $SB/cscope.files;cscope -b -q -R -i   $SB/cscope.files'

CSCOPE_DB=$SB/cscope.out
export CSCOPE_DB

Now go to the top directory of your codebase from where you want to build your cscope.

nirweb:/mysandbox/src$ bash
nirweb:/mysandbox/src$ mycscope
nirweb:/mysandbox/src$ ls -l cscope.out

Verify that cscope.out is created. Now run cscope

cscope -q -d

Browse your codebase using these common shortcuts

Jump to definition

Ctrl + ]

To return back

Ctrl + t

To find all references

Ctrl + \s

Note "+" is not a keystroke, it just indicates the combination

Happy browsing.

Some references

http://www.yolinux.com/TUTORIALS/LinuxTutorialAdvanced_vi.html

http://cscope.sourceforge.net/cscope_maps.vim

Leave a Reply

Your email address will not be published. Required fields are marked *