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@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@lasso2 tempdir]# cat list ./a ./b ./c [root@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@greenspot.fi wrote:
[root@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 17.5.2011 19.36, Bowie Bailey wrote:
Try this:
vim `cat list`
Thanks, this really works! I tried it with all my combinations:
OS X workstation by itself OS X workstation -> ssh -> CentOS 4 OS X workstation -> ssh -> CentOS 5
BTW, with the xargs command, all of these combinations give some problems. The cause may have something to do with my terminal settings. Anyway, now I can use `cat list`.
- Jussi
On 5/18/2011 12:50 AM, Jussi Hirvi wrote:
On 17.5.2011 19.36, Bowie Bailey wrote:
Try this:
vim `cat list`
Thanks, this really works! I tried it with all my combinations:
OS X workstation by itself OS X workstation -> ssh -> CentOS 4 OS X workstation -> ssh -> CentOS 5
BTW, with the xargs command, all of these combinations give some problems. The cause may have something to do with my terminal settings. Anyway, now I can use `cat list`.
The problem is that you were screwing up vim's stdin. Using the method I gave you, you are just taking advantage of shell features to provide a list of filenames to vim on the command line.
If your list looks like this:
file1 file2 file3
Then when you do "vim `cat list`", the shell expands it to this:
$ vim file1 file2 file3
You can also do this:
$ vim `ls -1 *.txt`
or this:
$ vim `find /some/dir -name '*.txt'`
It works with any command that outputs a list of filenames.
-----Original Message----- From: centos-bounces@centos.org [mailto:centos-bounces@centos.org] On Behalf Of Bowie Bailey Sent: Wednesday, May 18, 2011 9:55 To: centos@centos.org Subject: Re: [CentOS] Feed a list of filenames to vim
On 5/18/2011 12:50 AM, Jussi Hirvi wrote:
On 17.5.2011 19.36, Bowie Bailey wrote:
Try this:
vim `cat list`
Thanks, this really works! I tried it with all my combinations:
OS X workstation by itself OS X workstation -> ssh -> CentOS 4 OS X workstation -> ssh -> CentOS 5
BTW, with the xargs command, all of these combinations give some problems. The cause may have something to do with my
terminal settings.
Anyway, now I can use `cat list`.
The problem is that you were screwing up vim's stdin. Using the method I gave you, you are just taking advantage of shell features to provide a list of filenames to vim on the command line.
If your list looks like this:
file1 file2 file3
Then when you do "vim `cat list`", the shell expands it to this:
$ vim file1 file2 file3
You can also do this:
$ vim `ls -1 *.txt`
or this:
$ vim `find /some/dir -name '*.txt'`
It works with any command that outputs a list of filenames.
Until you have a space in a filename.
-- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- - - - Jason Pyeron PD Inc. http://www.pdinc.us - - Principal Consultant 10 West 24th Street #100 - - +1 (443) 269-1555 x333 Baltimore, Maryland 21218 - - - -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- This message is copyright PD Inc, subject to license 20080407P00.
On 5/18/2011 9:54 AM, Jason Pyeron wrote:
-----Original Message----- From: centos-bounces@centos.org [mailto:centos-bounces@centos.org] On Behalf Of Bowie Bailey Sent: Wednesday, May 18, 2011 9:55 You can also do this:
$ vim `ls -1 *.txt`
or this:
$ vim `find /some/dir -name '*.txt'`
It works with any command that outputs a list of filenames.
Until you have a space in a filename.
True. But unless vim has a null-separator option for command line arguments, I don't know of a way to automate that case.
On Wednesday 18 May 2011 15:09:19 Bowie Bailey wrote:
$ vim `ls -1 *.txt`
or this:
$ vim `find /some/dir -name '*.txt'`
It works with any command that outputs a list of filenames.
Until you have a space in a filename.
True. But unless vim has a null-separator option for command line arguments, I don't know of a way to automate that case.
How about just:
$ vim *.txt
or, if you need recursive:
$ eval vim $(find /some/dir -type f -printf '"%p" ')
(shell quotes expansions automatically, but you can still ensure output from find is appropriately quoted manually)
On 5/18/2011 10:42 AM, Michael Gliwinski wrote:
On Wednesday 18 May 2011 15:09:19 Bowie Bailey wrote:
$ vim `ls -1 *.txt`
or this:
$ vim `find /some/dir -name '*.txt'`
It works with any command that outputs a list of filenames.
Until you have a space in a filename.
True. But unless vim has a null-separator option for command line arguments, I don't know of a way to automate that case.
How about just:
$ vim *.txt
or, if you need recursive:
$ eval vim $(find /some/dir -type f -printf '"%p" ')
(shell quotes expansions automatically, but you can still ensure output from find is appropriately quoted manually)
Interesting. I'm not sure what the eval is doing, but it works even with spaces in the filenames. Unfortunately, it won't work with the OP's original scenario (a file with a list of filenames to edit).
In article 4DD3E087.5060305@BUC.com, Bowie Bailey Bowie_Bailey@BUC.com wrote:
On 5/18/2011 10:42 AM, Michael Gliwinski wrote:
How about just:
$ vim *.txt
or, if you need recursive:
$ eval vim $(find /some/dir -type f -printf '"%p" ')
(shell quotes expansions automatically, but you can still ensure output from find is appropriately quoted manually)
Interesting. I'm not sure what the eval is doing, but it works even with spaces in the filenames. Unfortunately, it won't work with the OP's original scenario (a file with a list of filenames to edit).
After a bit of experimentation, I found that this would work:
$ eval vim $(sed 's/.*/"&"/' file)
If this became a frequent requirement, perhaps an alias or function could be created.
Cheers Tony
On Wednesday 18 May 2011 16:06:47 Bowie Bailey wrote:
or, if you need recursive: $ eval vim $(find /some/dir -type f -printf '"%p" ')
(shell quotes expansions automatically, but you can still ensure output from find is appropriately quoted manually)
Interesting. I'm not sure what the eval is doing, but it works even with spaces in the filenames. Unfortunately, it won't work with the OP's original scenario (a file with a list of filenames to edit).
eval just evaluates arguments and hence does the same argument splitting as shell does when it receives a command, you can see it if you do 'set -x' before running the command. In this case eval gets two arguments: 'vim' and '"/some/dir/a" "/some/dir/b" ', after splitting the command run is vim "/some/dir/a" "/some/dir/b" (quoted) which is why spaces, etc. are preserved.
As for OP's original scenario, I left it out as you already answered it. Note that there's also a shortcut for cat (without launching a subprocess):
$ vim $(< listfile)
On 5/18/2011 11:34 AM, Michael Gliwinski wrote:
Note that there's also a shortcut for cat (without launching a subprocess):
$ vim $(< listfile)
That's one of those occasionally-useful tidbits that I will have completely forgotten about by the time I need to use it again! :-)
On 5/18/2011 11:33 AM, Bowie Bailey wrote:
On 5/18/2011 11:34 AM, Michael Gliwinski wrote:
Note that there's also a shortcut for cat (without launching a subprocess):
$ vim $(< listfile)
That's one of those occasionally-useful tidbits that I will have completely forgotten about by the time I need to use it again! :-)
Don't think of it as a special case. It is a combination of two generically useful simple operations. Unix, the shell, and vi are all about being able to reuse and combine simple steps instead of special-casing everything.
On 5/18/2011 12:58 PM, Les Mikesell wrote:
On 5/18/2011 11:33 AM, Bowie Bailey wrote:
On 5/18/2011 11:34 AM, Michael Gliwinski wrote:
Note that there's also a shortcut for cat (without launching a subprocess):
$ vim $(< listfile)
That's one of those occasionally-useful tidbits that I will have completely forgotten about by the time I need to use it again! :-)
Don't think of it as a special case. It is a combination of two generically useful simple operations. Unix, the shell, and vi are all about being able to reuse and combine simple steps instead of special-casing everything.
Right. I was referring to the shell shortcut "$(< filename)". Simple - Useful - and probably forgotten by the time I need it again.
On 5/18/2011 12:02 PM, Bowie Bailey wrote:
On 5/18/2011 12:58 PM, Les Mikesell wrote:
On 5/18/2011 11:33 AM, Bowie Bailey wrote:
On 5/18/2011 11:34 AM, Michael Gliwinski wrote:
Note that there's also a shortcut for cat (without launching a subprocess):
$ vim $(< listfile)
That's one of those occasionally-useful tidbits that I will have completely forgotten about by the time I need to use it again! :-)
Don't think of it as a special case. It is a combination of two generically useful simple operations. Unix, the shell, and vi are all about being able to reuse and combine simple steps instead of special-casing everything.
Right. I was referring to the shell shortcut "$(< filename)". Simple - Useful - and probably forgotten by the time I need it again.
That's the same thing I meant. It is $(command) which is the same as `command` where the output of the command replaces it on the command line before further evaluation. That's something you can use frequently. And '< filename' to control i/o redirection is something you can use even more frequently. So it's like doing '20i- <esc>' inside of vi to insert a dashed line. You don't have to know specifically that you can give a count with the insert command, you just know you can combine a count with any command.
On 5/18/2011 1:26 PM, Les Mikesell wrote:
On 5/18/2011 12:02 PM, Bowie Bailey wrote:
Right. I was referring to the shell shortcut "$(< filename)". Simple - Useful - and probably forgotten by the time I need it again.
That's the same thing I meant. It is $(command) which is the same as `command` where the output of the command replaces it on the command line before further evaluation. That's something you can use frequently. And '< filename' to control i/o redirection is something you can use even more frequently. So it's like doing '20i- <esc>' inside of vi to insert a dashed line. You don't have to know specifically that you can give a count with the insert command, you just know you can combine a count with any command.
I see. I haven't done any serious shell programming in years, so I've forgotten most of the little stuff like this (if I ever knew it to begin with).
On 5/18/2011 10:26 AM, Jussi Hirvi wrote:
On 18.5.2011 16.54, Bowie Bailey wrote:
You can also do this:
$ vim `ls -1 *.txt`
That one can be accomplished in a simpler way:
vim *.txt
Yea, I thought about that after I typed it, but I left it in as an example of the general method.
-----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@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@lasso2 tempdir]# cat list ./a ./b ./c [root@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
In article 4DD2A021.4080303@greenspot.fi, Jussi Hirvi listmember@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@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@lasso2 tempdir]# cat list ./a ./b ./c [root@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
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",@files);' example_list.txt
On 05/18/2011 08:06 AM, Benjamin Franz wrote:
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",@files);' example_list.txt
Quick change to handle filenames that start with '-' as well:
perl -e 'my @files = grep(!/^\s*$/,<ARGV>); chomp @files; system("vim","--",@files);' example_list.txt
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.
[...]
what, so no-one is going to offer a better solution with emacs? I'm sure the ensuing debate could be fruitful and provide a refreshing change from the usual centos dev bashing... :-)
[no please don't reply anything serious, just meant to make you smile]
On 5/18/2011 11:15 AM, Nicolas Thierry-Mieg wrote:
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.
[...]
what, so no-one is going to offer a better solution with emacs? I'm sure the ensuing debate could be fruitful and provide a refreshing change from the usual centos dev bashing... :-)
Use emacs to send a list of filenames to vim? That would be an...interesting...solution! :-)
--On Wednesday, May 18, 2011 05:15:54 PM +0200 Nicolas Thierry-Mieg Nicolas.Thierry-Mieg@imag.fr wrote:
what, so no-one is going to offer a better solution with emacs?
Never mind the emacs vs vi flamewars. (Of which I use both fluently.) Real Sysadmins Use ed(1).
;)
Of course, trying to use ed with a list of files is just silly ...
(Actually, knowing how to use ed saved my bacon more than once on SunOS4 systems where the machine was so hosed that it wouldn't load vi.)
Devin