我正在寻找一种方法来 grepcscope
来自 Vim 的查询输出。
以下对我不起作用:
:cs f s symbol !grep pattern
它给出了:
E259: no matches found for cscope query s symbol !grep pattern ...
PS:
我知道redir
方法,我正在寻找一种更简单的方法来
通过 Unix 命令过滤 ex 命令的输出。
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.
这是我过滤快速修复列表的函数和宏:
用法:
_qf
, _qF
,_qp
并_qP
会打开一个对话框提示_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>