5

我正在寻找一种方法来 grepcscope来自 Vim 的查询输出。

以下对我不起作用:

:cs f s symbol !grep pattern

它给出了:

E259: no matches found for cscope query s symbol !grep pattern ...

PS:
我知道redir方法,我正在寻找一种更简单的方法来
通过 Unix 命令过滤 ex 命令的输出。

4

2 回答 2

6

You can use :redir to send message output to a register or file.

redir @c
cs f s symbol
redir END

Now you can put the c register into a file and filter it.

I don't get much output from cscope (it's all in the quickfix), but that will do what you're describing.


In general, you can filter shell commands (see :help :!cmd) with | (bar):

:!echo 0updateView | cscope -dl | grep global

But ex commands interpret bar as a command separator (so you can put multiple commands on one line):

:if &ft != 'help' | silent! cd %:p:h | endif

I don't think you can filter the output of ex commands aside from using redir. However, you could use Benoit's answer to filter the quickfix.

于 2011-09-09T04:39:37.313 回答
0

这是我过滤快速修复列表的函数和宏:

用法:

  • _qf, _qF,_qp_qP会打开一个对话框提示
  • 您将在该对话框提示中键入 Vim 模式
  • _qf并将_qF过滤文件名_qp_qP行内容
  • 大写版本有:v效果(保持行不匹配),正常版本保持行匹配您的模式。
  • 如果结果不满足您的要求,您可以跳过较旧和较新的快速修复列表:colder:cnewer我也有调用这些命令的映射。

编码:

" Filter Quickfix list
function! FilterQFList(type, action, pattern)
    let s:curList = getqflist()
    let s:newList = []
    for item in s:curList
        if a:type == 'f'     " filter on file names
            let s:cmpPat = bufname(item.bufnr)
        elseif a:type == 'p' " filter on line content (pattern)
            let s:cmpPat = item.text . item.pattern
        endif
        if item.valid
            if a:action == '-'
                " Delete matching lines
                if s:cmpPat !~ a:pattern
                    let s:newList += [item]
                endif
            elseif a:action == '+'
                " Keep matching lines
                if s:cmpPat =~ a:pattern
                    let s:newList += [item]
                endif
            endif
        endif
    endfor
    " Assing as new quickfix list
    call setqflist(s:newList)
endfunction

nnoremap _qF            :call FilterQFList('f', '-', inputdialog('Delete from quickfix files matching: ', ''))<CR>
nnoremap _qf            :call FilterQFList('f', '+', inputdialog('Keep only quickfix files matching: ', ''))<CR>
nnoremap _qP            :call FilterQFList('p', '-', inputdialog('Delete from quickfix lines matching: ', ''))<CR>
nnoremap _qp            :call FilterQFList('p', '+', inputdialog('Keep only quickfix lines matching: ', ''))<CR>
于 2011-09-09T08:19:14.740 回答