How to filter cscope output in Vim

I am looking for a way to grep output cscoperequests from Vim.

The following did not work for me:

:cs f s symbol !grep pattern

He gave:

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

PS:
I know the method redir, I'm looking for an easier way to filter the output of ex-command commands through Unix commands.

+5
source share
2 answers

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

redir @c
cs f s symbol
redir END

Now you can put the register cin the file and filter it.

I do not get many results from cscope (all this in quickfix), but it will do what you describe.


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

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

ex ( ):

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

, ex , redir. , Benoit .

+6

:

:

  • _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>
0

All Articles