Skip to content

Instantly share code, notes, and snippets.

@fweep
Last active August 23, 2017 11:08
Show Gist options
  • Save fweep/5182260 to your computer and use it in GitHub Desktop.
Save fweep/5182260 to your computer and use it in GitHub Desktop.
Vim configuration for interacting with cscope databases (focus on Ruby).
if has("cscope")
"TODO: turn this all into a plugin.
set nocscopetag
set cscopequickfix=s-,c-,d-,i-,t-,e-
set nocscopeverbose
if filereadable(".git/cscope.out")
cscope add .git/cscope.out
endif
set cscopeverbose
"TODO: figure out which of these are useless in Ruby and disable them.
nnoremap <Leader>fs :cscope find s <C-R>=expand("<cword>")<CR><CR>:botright cwindow<CR>
nnoremap <Leader>fg :cscope find g <C-R>=expand("<cword>")<CR><CR>:botright cwindow<CR>
nnoremap <Leader>fc :cscope find c <C-R>=expand("<cword>")<CR><CR>:botright cwindow<CR>
nnoremap <Leader>ft :cscope find t <C-R>=expand("<cword>")<CR><CR>:botright cwindow<CR>
nnoremap <Leader>fe :cscope find e <C-R>=expand("<cword>")<CR><CR>:botright cwindow<CR>
nnoremap <Leader>ff :cscope find f <C-R>=expand("<cfile>")<CR><CR>:botright cwindow<CR>
nnoremap <Leader>fd :cscope find d <C-R>=expand("<cword>")<CR><CR>:botright cwindow<CR>
nnoremap <Leader>fi :cscope find i ^<C-R>=expand("<cfile>")<CR>$<CR>:botright cwindow<CR>
"TODO: figure out how to get cstag output in quickfix or a popup menu.
map <C-_> :cstag <C-R>=expand("<cword>")<CR><CR>
function! CscopeRebuild()
cscope kill .git/cscope.out
silent execute "!./.git/hooks/cscope"
if v:shell_error
redraw!
echohl ErrorMsg | echo "Unable to run cscope command." | echohl None
else
if filereadable(".git/cscope.out")
redraw!
cscope add .git/cscope.out
else
redraw!
echohl ErrorMsg | echo "Unable to read cscope database." | echohl None
endif
endif
endfunction
command! Cscope call CscopeRebuild()
endif
#!/bin/sh
# NOTE: this is really .git/hooks/cscope but Gist doesn't like paths.
set -e
trap "rm -f .git/cscope.out.$$" EXIT
find . \( -name "*.rb" -o -name "*.erb" -o -name "*.haml" \) -print \
-o -path "./.git" -prune \
-o -path "./tmp" -prune \
-o -path "./coverage" -prune \
-o -path "./vendor" -prune | cscope -R -b -i - -f .git/cscope.out.$$
mv .git/cscope.out.$$ .git/cscope.out
@eapache
Copy link

eapache commented Aug 23, 2017

You may be interested in https://github.com/eapache/starscope since it will generate a much more accurate cscope database for ruby projects than the normal cscope program.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment