【问题标题】:Disable cscope autojump禁用 cscope 自动跳转
【发布时间】:2013-06-20 02:34:24
【问题描述】:

每次我使用 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      

【问题讨论】:

    标签: vim cscope


    【解决方案1】:

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

    Cscope 默认显示可能匹配的列表,因此如果您的 ~/.vimrc 中没有与 cscope 相关的选项,您想要的行为就是应该发生的情况。

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

    您确定您的~/.vimrc 中没有任何与 cscope 相关的内容吗?您确定您的查询有多个匹配项吗?直接运行 cscope TUI 时会得到多个匹配项吗?

    【讨论】:

    • 我的 .vimrc 中 cscope 的唯一内容是一些关键的 nmap。我确定我的查询有多个匹配项。
    • 你使用什么命令,你的~/.vimrc中有什么映射?
    • 我向你保证,我所做的只是:cs add cscope.out,cs find g multi_matches_name。 .vimrc 中的 nmap 用于 cs find 命令。
    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

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

      1. 使用外部shell命令cscope,因为它在kino plugin中实现
      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
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-02-04
        • 1970-01-01
        • 2015-05-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-09-25
        相关资源
        最近更新 更多