Using vim + cscope to browse kernel source code
-
Download vim source from here: [vim-7.1.tar.bz2].
-
Build vim with "-enable-cscope " option and install it.
[aubrey-neveda@vim71] export PATH=$PATH:/usr/sfw/bin
[aubrey-neveda@vim71] ./configure --prefix=/usr --enable-cscope
[aubrey-neveda@vim71] make
[aubrey-neveda@vim71] su
Password:
# make install
[aubrey-neveda@vim71] which vim
/usr/bin/vim
- Getting colors vim to work on Solaris
- touch vimrc file and add the following line
[aubrey-neveda@vim71] cat ~/.vimrc
:syntax on
- export environment variable TERM=xtermc
[aubrey-neveda@vim71] set | grep TERM
TERM=xtermc
Now you should have a color vim. Open a C file to give a shot.
-
Download the cscope_maps.vim file, and stick it in your $HOME/.vim/plugin directory (create the directory if it doesn't exist).
[aubrey-neveda@vim71] ls -l ~/.vim/plugin/
total 16
-rwxr--r-- 1 nobody nobody 7336 Jul 12 09:58 cscope_maps.vim
- Building cscope database manually. The ON 'xref' utility builds the database in cscope-fast format. So it has to be re-built.
- cd to the directory where you want to start
-
find . -name *.h >>cscope.files.bak
-
find . -name *.c >>cscope.files.bak
-
grep -v SCCS cscope.files.bak >cscope.files
- cscope -b
Now vim + cscope is ready to browse the source code. The following feature is very handy.
-
vim -t symbol: start vim and position the cursor at the file and line where the symbol is defined
- ctrl + ]: find the symbol under the cursor
- ctrl + / then s: find the caller of the symbol under the cursor
- ctrl + t: jump back to the original location before the search