[CentOS] Feed a list of filenames to vim

Tue May 17 16:39:42 UTC 2011
Tony Mountifield <tony at mountifield.org>

In article <4DD2A021.4080303 at greenspot.fi>,
Jussi Hirvi <listmember at greenspot.fi> wrote:
> There are some googlable ways to feed a list of filenames to vim, but I 
> stumble on weird results.
> With my filelist, I try to do
> 	cat list | xargs vim
> ...to edit the files listed in the file "list". Here's what happens:
> [root at lasso2 tempdir]# ls -l
> total 8
> -rw-r--r--  1 root root  0 May 17 18:28 a
> -rw-r--r--  1 root root  0 May 17 18:28 b
> -rw-r--r--  1 root root  3 May 17 18:31 c
> -rw-r--r--  1 root root 12 May 17 18:43 list
> [root at lasso2 tempdir]# cat list
> ./a
> ./b
> ./c
> [root at lasso2 tempdir]# cat list | xargs vim
> 3 files to edit
> Vim: Warning: Input is not from a terminal
> Ok, so far, so good. And after this, the file a opens, as expected. 
> However, the contents show as all uppercase. And everything I write is 
> uppercase too. I can move to the next file (:n) even though the command 
> shows as uppercase (:N). I cannot quit vim, however. When I do ":q", I 
> get blank screen, and I have to close the terminal window.
> If I do instead
> 	cat list | xargs less
> ...it works as expected.
> And with
> 	cat list | xargs vi
> ...(in a fresh terminal window), the editing goes just perfect, but when 
> I quit vi, the terminal will not show the commands I write, and the 
> display gets garbled (no newlines etc.).
> What is happening?

The problem is that standard input is being used to send the list of
files to xargs, and vi inherits this standard input. That's why it warns
that input is not from a terminal - it normally expects the user input
to be on standard input.

Try this instead:

vim `cat list`

This will work provided none of the files has a space in its name or
directory path.

Tony Mountifield
Work: tony at softins.co.uk - http://www.softins.co.uk
Play: tony at mountifield.org - http://tony.mountifield.org