【问题标题】:How to search in vim cscope result window如何在 vim cscope 结果窗口中搜索
【发布时间】:2011-01-10 07:43:59
【问题描述】:

当我们在 vim 中使用 cscope 去定义一个符号时,结果窗口中可能会显示很多候选。我想在窗口中执行搜索以快速找到我需要的内容。但是搜索功能 (/) 在结果窗口中似乎不起作用,只有几个键可用,j,k,gg,G 等。

是否有在 cscope 结果窗口中搜索?或者任何人都可以分享一些在这种情况下如何更有效地工作的经验。

谢谢。

【问题讨论】:

    标签: vim cscope


    【解决方案1】:

    您可以使用以下内容:

    " Filter the quickfix list
    function! FilterQFList(type, action, pattern)
        " get current quickfix list
        let s:curList = getqflist()
        let s:newList = []
        for item in s:curList
            if a:type == 0     " filter on file names
                let s:cmpPat = bufname(item.bufnr)
            elseif a:type == 1 " filter by line content
                let s:cmpPat = item.text . item.pattern
            endif
            if item.valid
                if a:action < 0
                    " Keep only nonmatching lines
                    if s:cmpPat !~ a:pattern
                        let s:newList += [item]
                    endif
                else
                    " Keep only matching lines
                    if s:cmpPat =~ a:pattern
                        let s:newList += [item]
                    endif
                endif
            endif
        endfor
        call setqflist(s:newList)
    endfunction
    

    然后定义四个映射(将 ø 替换为适合您的东西,我的以 ð 开头,我认为您的键盘上可能不可用)分别映射到:

    nnoremap ø :call FilterQFList(0, -1, inputdialog('Remove file names matching:', ''))<CR>
    nnoremap ø :call FilterQFList(0, 1, inputdialog('Keep only file names matching:', ''))<CR>
    nnoremap ø :call FilterQFList(1, -1, inputdialog('Remove all lines matching:', ''))<CR>
    nnoremap ø :call FilterQFList(1, 1, inputdialog('Keep only lines matching:', ''))<CR>
    

    通过这种方式,您可以使用任何模式过滤您的快速修复列表(您拥有 vim reg.exps 的强大功能)。使用:cnewer:colder 可以跳过之前的快速修复列表。

    【讨论】:

    • 伯努瓦,谢谢分享。我能理解你的剧本。但我不知道如何将它与 cscope 一起使用。 cscope 的输出似乎没有进入快速修复窗口。你能展示一下你是如何使用它的吗?
    • 你使用:cscope add my_cscope_database.out然后:cscope find s your_symbol?还要确保:set csqf=s-,c-,d-,i-,t-,e-。另见:help cscope-options
    • 我没有注意到这个选项。非常感谢!
    • BTW,你知道默认cscope输出窗口的“正式名称”吗?
    • 它被称为快速修复窗口。见:help quickfix!
    猜你喜欢
    • 1970-01-01
    • 2011-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多