如何在 vim cscope 结果窗口中搜索

发布于 2024-10-11 08:14:08 字数 186 浏览 5 评论 0原文

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

有没有办法在cscope结果窗口中搜索?或者有人可以分享一些关于如何在这种情况下更有效地工作的经验吗?

谢谢。

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.

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.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

海螺姑娘 2024-10-18 08:14:08

您可以使用以下内容:

" 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 跳转之前的快速修复列表。

You can use the following:

" 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>

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文