This post explains about the details of how to setup ctags and cscope together.
For this, we will use the linux kernel source code where ctags and cscope
configured and see how easily we can navigate the source code.
Step1:
- Download the Linux kernel source tar and untar it
- Kernel source path: /home/ramesh/kernelsrc/
Step2:
Download the below content and copy into ~/.vim/plugin/cscope_maps.vim
https://cscope.sourceforge.net/cscope_maps.vim
Step3:
mkdir /home/ramesh/cscope
cd /home/ramesh/cscope
find /home/ramesh/kernelsrc/ -name "*.[chxsS]" -print > cscope.files
cscope -b -q -k
Step4: ctags:
- cd /home/ramesh/kernelsrc/
- ctags -R *
Step5: vimrc configuration
Copy the below content in ~/.vimrc file
syntax on
set hlsearch
set ruler
set tagrelative
set tags=/home/ramesh/kernelsrc
set splitright
let $CSCOPE_DB = '/home/ramesh/cscope/cscope.out'
set tabstop=4
set shiftwidth=4
set softtabstop=4
set expandtab
set backspace=indent,eol,start
Commands:
- cscope -R
- ctrl + ] => To jump to definition
- gd => To jump to local variable declaration
- gD => To jump to global variable declaration
- ctrl + t => To jump to previous location
- ctrl + \ + s => Search for all the occurances (in the same window)
- ctrl + <spacebar> + s => Search for all the occurances (in the split window)