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? - Jussi
--On Tuesday, May 17, 2011 07:19:45 PM +0300 Jussi Hirvi <listmember at greenspot.fi> wrote:> [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.I don't *know* the answer, but my suspicion is that this is related to very old compatibility code in the bowels of vim or its dependent libraries (including other things in the call stack including getty), having to do with terminals that are not capable of handling lower case letters. A piece of history: Years back, there were upper-case-only terminals. Later there was mixed case, but enough of the upper-case-only ones that UNIX needed to allow for it. For example, at the login prompt if you put your login ID as all upper case the terminal will default to all upper case (and do some case conversion of your password as well, iirc). My suspicion is that since vim is detecting that its input is not a tty, something in it or its libraries is reverting back to this old behavior. However it's been so long since there was a signficant (or any?) user base that used this feature, vim's capabilities in this respect have suffered from bit rot due to lack of testing this feature. Devin
On 5/17/2011 12:19 PM, Jussi Hirvi 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 vimTry this: vim `cat list` -- Bowie
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 5/17/2011 12:19 PM, Jussi Hirvi 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?Do this instead: vi `cat list` cat list - gives the output of the file which is the three filenames `cat list` - executes this command and feeds its output to the input of your next command So the resulting command ends up being "vi ./a ./b ./c" which opens up the 'a' file and you will be able to move to the next file with the :n option. xargs is effectively running a for loop on each unique item in the output of the previous command (cat list). vi expects to be run on one file at a time and needs to be associated with a terminal session in prder to be able to get input from you (either text or commands) to apply to the file. - -- David Goldsmith -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.14 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk3SpE0ACgkQ417vU8/9QflaoQCdH0YmjkeVG4QypCWRZFPpDBD4 N0QAn3dCourgI97OpthGJFa7FTWS/f5t =lkQA -----END PGP SIGNATURE-----
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. Cheers Tony -- Tony Mountifield Work: tony at softins.co.uk - http://www.softins.co.uk Play: tony at mountifield.org - http://tony.mountifield.org
On 05/17/2011 09:19 AM, Jussi Hirvi wrote:> There are some googlable ways to feed a list of filenames to vim, but I > stumble on weird results.[...] The easy way for me is 'avoid the shell - use Perl instead': perl -e 'my @files = grep(!/^\s*$/,<ARGV>); chomp @files; system("vim", at files);' example_list.txt -- Benjamin Franz