Grappling inside Vim (with pipe)

I want to create a list of "quickfix" (see :help quickfix) with all files containing lines with "abc" but not "xyz". I was hoping I could run the following vim ex command:

:grep -nHr abc * | grep -v xyz

Unfortunately, vim doesn't like the pipe, and the team crashes. What is the best way to do this from within vim?

+5
source share
4 answers

For some reason I can't leave it alone!

How about a use :!grep ... > filenamefollowed by :cf filenamethat will open the output as a quick delete list.

+3
source

You can do this in two steps:

:!(grep -nHr abc * | grep -v xyz >| qf.txt)
:cfile qf.txt | copen

, , , :

fu! Mygrep(pat1, pat2)
  let cmd = "silent !(grep -nHr " . a:pat1 . " * | grep -v " . a:pat2 . " >| qf.txt)"
  silent exec cmd
  cfile qf.txt
  copen 
endfunction

, :

:call Mygrep("abc", "xyz")

, "trailin charathers" ( , ).

+1

, :grepprg, .

my :grepprg lid GNU Idutils. , lid . , , , lid . , , pthread.*lock, , , , ID, mkid, .

. , Vim grepprg . , Vim.

, .vimrc :

:set grepprg=lid\ --substring\ --result=grep\ '\\<$*\\>'\ \\\|\ sort

\\\|: \|, , |.

grep Unix.


, .

:grep , :

:cope[Enter]

, , , Ctrl-W Ctrl-W Ctrl-W.

" " , . , Enter , . : , - , Ctrl-W Ctrl-W.

, :cope. , , , :

 :set modifiable

-

 :g/xyz/d

delete all results containing xyz. Only the remaining lines are now part of the quickfix list.

0
source

You can set grepprgwhich determines which command Vim uses to execute :grep. This may take the pipe, although I have not tried it.

Of course, this will affect all your :greps

-1
source

All Articles