如何在 vim cscope 结果窗口中搜索 [英] How to search in vim cscope result window

查看:16
本文介绍了如何在 vim cscope 结果窗口中搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

When we use cscope to go to definition of a symbol in vim, lots of candidates may be shown in result window. I'd like to perform searching within the window to find what I need quickly. But search function (/) doesn't seem to work in result window, only a few keys are available, j,k,gg,G, etc.

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

Is there anyway to search in cscope result window? Or can anyone share some experiences with how to work more efficiently in such a situation.

谢谢.

推荐答案

您可以使用以下内容:

" 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

然后定义四个映射(用适合你的东西替换 ø,我的从 ð 开始,我认为它可能在你的键盘上不可用)分别映射到:

Then define four mappings (replace ø with something that fits for you, mine start with ð which I think might be unavailable on your keyboard) that map respectively to:

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>

这样你就可以用任何模式过滤你的 quickfix 列表(你有 vim reg.exps 的功能).使用 :cnewer:colder 跳过之前的快速修复列表.

This way you can filter your quickfix list with any pattern (you have the power of vim reg.exps). Use :cnewer and :colder to jump through previous quickfix lists.

这篇关于如何在 vim cscope 结果窗口中搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆