0

每次我使用 cscope 时,即使有多个结果,它也会自动跳转到第一个结果。

我想得到一个匹配结果的列表,所以我可以从中选择一个。到目前为止,我在 .vimrc 中没有为 cscope 设置任何内容。

我怎样才能做到这一点?

$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      
4

3 回答 3

0

原因在于我在这里https://github.com/brookhong/cscope.vim使用了另一个版本的 cscope.vim ,它改变了功能。

于 2013-06-20T08:30:21.140 回答
0

您在问题中包含的版本信息通常是无用的:完整输出$ vim --version是有用信息所在的位置(补丁级别、启用/禁用的功能……)。

Cscope 默认显示可能匹配的列表,因此如果您的~/.vimrc.

例如,在我当前的 JavaScript 文件中,该命令:cs f 0 addClass显示了一个包含 3 个项目的列表、函数定义和两个调用。

你确定你的文件中没有任何与 cscope 相关的东西~/.vimrc吗?您确定您的查询有多个匹配项吗?直接运行 cscope TUI 时是否获得多个匹配项?

于 2013-06-20T05:28:29.410 回答
0

我知道问题的两种解决方案:

  1. 使用外部 shell 命令cscope,因为它在kino 插件中实现
  2. 立即关闭自动打开的缓冲区。
" 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
于 2019-02-06T13:53:41.847 回答