Using Cscope in Vim
Submitted by zhigang on Mon, 2008-03-17 11:06
Generate a cscope database
$ cscope -b -R
For Linux kernel and some other packages which have built-in cscope target in Makefile:
$ make cscope
Configure Vim to locate a cscope database:
:cs add cscope.out
My cscope settings in ~/.vimrc:
"cscope settings
if has("cscope") && filereadable("/usr/bin/cscope")
set csprg=/usr/bin/cscope
set csto=0
set cst
set nocsverb
" add any database in current directory
if 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 ../../../..
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
set csverb
endif
" Using 'CTRL-backslash' then a search type makes the vim window
" split horizontally, with search result displayed in the new window.
nmap <C-\>s :scs find s <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>g :scs find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>c :scs find c <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>t :scs find t <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>e :scs find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>f :scs find f <C-R>=expand("<cfile>")<CR><CR>
nmap <C-\>i :scs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap <C-\>d :scs find d <C-R>=expand("<cword>")<CR><CR>
Jump to a tag
:cs find d <tagname>
- position the cursor over a tag name and then press:
Ctrl-\ d
$ vim -t <tagname>
Come back from a tag jump
:pop
Ctrl-t
Reference
»
- Add new comment
- 67 reads


Recent comments
15 weeks 4 days ago
40 weeks 4 days ago
47 weeks 1 day ago
49 weeks 5 days ago
1 year 1 week ago
1 year 49 weeks ago