0

Every time I use cscope, it just auto jumps to the first result even when there are more than one results.

I want to get a list of the matched results, so I can select one from it. I have setting nothing for cscope in .vimrc so far.

How can I achieve this?

$vim --version
VIM - Vi IMproved 7.3 (2010 Aug 15, compiled May  4 2012 04:25:35)
Included patches: 1-429
Modified by pkg-vim-maintainers@lists.alioth.debian.org
Compiled by buildd@
Huge version without GUI.  Features included (+) or not (-):
+arabic +autocmd -balloon_eval -browse ++builtin_terms +byte_offset +cindent 
-clientserver -clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments 
+conceal +cryptv +cscope +cursorbind +cursorshape +dialog_con +diff +digraphs 
-dnd -ebcdic +emacs_tags +eval +ex_extra +extra_search +farsi +file_in_path 
+find_in_path +float +folding -footer +fork() +gettext -hangul_input +iconv 
+insert_expand +jumplist +keymap +langmap +libcall +linebreak +lispindent 
+listcmds +localmap -lua +menu +mksession +modify_fname +mouse -mouseshape 
+mouse_dec +mouse_gpm -mouse_jsbterm +mouse_netterm -mouse_sysmouse 
+mouse_xterm +mouse_urxvt +multi_byte +multi_lang -mzscheme +netbeans_intg 
+path_extra -perl +persistent_undo +postscript +printer +profile +python 
-python3 +quickfix +reltime +rightleft -ruby +scrollbind +signs +smartindent 
-sniff +startuptime +statusline -sun_workshop +syntax +tag_binary 
+tag_old_static -tag_any_white -tcl +terminfo +termresponse +textobjects +title
-toolbar +user_commands +vertsplit +virtualedit +visual +visualextra +viminfo 
+vreplace +wildignore +wildmenu +windows +writebackup -X11 -xfontset -xim -xsmp
-xterm_clipboard -xterm_save 
system vimrc file: "$VIM/vimrc"
  user vimrc file: "$HOME/.vimrc"
  user exrc file: "$HOME/.exrc"
fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H     -g -O2 -fstack-protector       --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security   -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1      
Linking: gcc   -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,--as-needed -o vim       -lm -ltinfo -lnsl  -lselinux  -lacl -lattr -lgpm -ldl     -L/usr/lib/python2.7/config -lpython2.7 -lpthread -ldl -lutil -lm -Xlinker -export-dynamic -Wl,-O1 -Wl,-Bsymbolic-functions      
FaceBro
  • 787
  • 2
  • 13
  • 29

3 Answers3

0

The version information you have included in your question is generally useless: the full output of $ vim --version is where useful information is (patch-level, enabled/disabled features…).

Cscope defaults to showing a list of possible matches so the behavior you want is what should happen if you have no cscope-related options in your ~/.vimrc.

In my current JavaScript file, for example, the command :cs f 0 addClass shows a list of 3 items, the function definition and two calls.

Are you sure you don't have any cscope-related stuff in your ~/.vimrc? Are you sure there are multiple matches for your query? Do you get multiple matches when running the cscope TUI directly?

romainl
  • 186,200
  • 21
  • 280
  • 313
  • The only stuff for cscope in my .vimrc is some key nmap. I am sure there are multiple matches for my query. – FaceBro Jun 20 '13 at 06:01
  • What command do you use and what mapping do you have in your `~/.vimrc`? – romainl Jun 20 '13 at 07:33
  • I am assuring you that all I have done is: cs add cscope.out, cs find g multi_matches_name. nmap in .vimrc is for cs find command. – FaceBro Jun 20 '13 at 07:43
0

The cause lies in that I use another version of cscope.vim here https://github.com/brookhong/cscope.vim, which changes the functions.

FaceBro
  • 787
  • 2
  • 13
  • 29
0

I know two solutions of problem:

  1. Use external shell command cscope as it is implemented in kino plugin
  2. Close automatically opened buffer immediately.
" Run native cscope and close automatically opened buffer
func s:Run_cscopeWithCloseBuffer(query, pattern)

    " Save info about opened buffers
    let bufinfo = getbufinfo({'buflisted':1})

    try

        " run cscope
        exe 'cs find ' . a:query . ' ' . a:pattern

        " If query populates quickfix
        if a:query !=# 'g' && a:query !=# 'f'

            " save opened buffer number
            let opened_bufnr = bufnr('%')

            " open quickfix window, switch to previous buffer 
            " and go back to quickfix
            silent! botright copen
            exe 'wincmd p'
            exe "normal \<C-O>"
            exe 'wincmd p'

            " check if atomatically opened buffer was opened before
            let noclose = 0
            for buf_i in bufinfo
                if opened_bufnr == buf_i.bufnr
                    let noclose = 1
                    break
                endif
            endfor

            " Close atomatically opened buffer
            if !noclose
                exe 'bdelete ' . opened_bufnr
            endif

        endif

    " If cscope has not found any matches
    catch /^Vim(cscope):E259:/
        echo 'No matches found for cscope query ' . a:query . ' ' . a:pattern
    catch 
        echo v:exception
    endtry

endfunc
Kirill Bugaev
  • 370
  • 3
  • 13