Saturday, September 25, 2010

Re: How to open filelist with pipe?

On Sat, 25 Sep 2010, Abendas wrote:

> find ./ -name *.html | xargs grep -l rapp_document
>
>
> ./file1
> ./file2
> ./file3
>
>
> How to open the filelist ? like "vim file1 file2 file3"

If the file names won't contain spaces:

vim $(#your command#)

i.e.:

vim $(find ./ -name *.html | xargs grep -l rapp_document)

Otherwise, it's tricky, but here's a passable version (assumes the file
names won't contain newlines or carriage returns):

#your command# | vim - +'for a in getline(".","$") | exe "argadd ".fnameescape(a) | endfor' +'bd!' +rewind

Anatomy:

#your command# " produces filenames
| vim " piped to Vim
- " editing standard input
+' " when opened, run this command
for a in getline(".","$") " for each line of the file (which is stdin)
| " Vim cmd separator (see: :help :bar)
exe "argadd ".fnameescape(a) " add it to the argument list, escaping special chars
| "
endfor' " end of for loop -- at this point,
" -- argument list is correct, but in reverse order
+'bd!' " delete the buffer holding the piped input
+rewind " go back to the start of the argument list

--
Best,
Ben

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: