我希望找到一种从Vim中grep cscope
查询输出的方法。
以下方法对我无效:
:cs f s symbol !grep pattern
这将会给出:
E259: no matches found for cscope query s symbol !grep pattern ...
P.S:
我知道使用redir
命令可以过滤ex命令的输出,但我正在寻找一种更简单的方法来通过Unix命令过滤输出。
:redir
将消息输出发送到寄存器或文件。redir @c
cs f s symbol
redir END
|(竖杠)过滤shell命令(请参见: help:!cmd)。
:!echo 0updateView | cscope -dl | grep global
但是ex命令将竖线解释为命令分隔符(因此您可以在一行上放置多个命令):
:if &ft != 'help' | silent! cd %:p:h | endif
我认为你无法过滤 ex 命令的输出,除非使用 redir
。然而,你可以使用 Benoit 的答案来过滤快速修复。
这里是我用于过滤quickfix列表的函数和宏:
使用方法:
_qf
、_qF
、_qp
和_qP
将打开一个对话框提示_qf
和_qF
将过滤文件名,_qp
和_qP
将过滤行内容:v
效果(保留不匹配的行),普通版本保留与您的模式匹配的行。:colder
和:cnewer
,如果结果不满意,您可以跳转到较旧和较新的quickfix列表。我也有映射来调用这些命令。代码:
" 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>
:set cscopequickfix=s-,c-,d-,i-,t-,e-,a-
。实际上,我可以使用:call FilterQFList
调用此函数,但是键映射就是不起作用。我的意思是,在使用cscope搜索之前,这个映射可以在正常模式下工作。另外,我使用了huge
特性来构建我的vim。 - VicX