I have to say the only time I ever pipe directly to vim in a real world scenario is when I want to see a diff in color: diff file1 file2 | vim - Gives you the diff but colorized with Vim. Handy little trick.
Or just: vim -d file1 file2.
Use Vim Inside a Unix Pipe Like Sed or AWK
21–30 of 49 posts
Re: Use Vim Inside a Unix Pipe Like Sed or AWK
#22Re: Use Vim Inside a Unix Pipe Like Sed or AWK
#23Why is this article talking about idempotence? I don't see why that matters in the slightest for a unix pipe. Idempotence only matters if you're going to take the output of the pipe and run it back through the pipe again. There's a bit later on about idempotence and newlines, but I don't see what that has to do with idempotence. Vim will append a trailing newline if the file doesn't have one, sure, but if I pass the…
What he really means is that his first snippet is the identity function. Like x*1=x or x+0=x. Whatever it gets, it passes along unmodified. I think it's actually kind of nice that he started with that. Sometimes it is not easy to figure out how to do, for instance with XLST.....
Re: Use Vim Inside a Unix Pipe Like Sed or AWK
#24Why is this article talking about idempotence? I don't see why that matters in the slightest for a unix pipe. Idempotence only matters if you're going to take the output of the pipe and run it back through the pipe again. There's a bit later on about idempotence and newlines, but I don't see what that has to do with idempotence. Vim will append a trailing newline if the file doesn't have one, sure, but if I pass the…
If you do
echo -en "" | ( (vim - -esbnN -c 'w!/dev/stderr|q!' >/dev/null) 2>&1) | xxd
versus echo -en "" | ( (vim - -esbnN -c 'w!/dev/stderr|q!' >/dev/null) 2>&1) | ( (vim - -esbnN -c 'w!/dev/stderr|q!' >/dev/null) 2>&1) | xxd
These will the same output, so it is idempotent. However, if you build upon that and do echo -en "" | ( (vim - -esbnN -c '%!xxd' -c 'w!/dev/stderr|q!' >/dev/null) 2>&1) | xxd
versus echo -en "" | ( (vim - -esbnN -c '%!xxd' -c 'w!/dev/stderr|q!' >/dev/null) 2>&1) | ( (vim - -esbnN -c '%!xxd' -c 'w!/dev/stderr|q!' >/dev/null) 2>&1) | xxd
The result is not the same, and therefore not idempotent if you plan to add extra -c commands.Re: Use Vim Inside a Unix Pipe Like Sed or AWK
#25This post hints toward vim's history: the ed family of editors. http://blog.sanctum.geek.nz/actually-using-ed/ http://blog.sanctum.geek.nz/using-more-of-ex/ A big use case for them was using them as scriptable editors in pipelines, and a lot of vim's commands are inherited from them. The diff(1) utility actually has an option to emit ed script, allowing files to be patched in ed pipelines: http://www.gnu.org/software…
It's common for people today to think of ancient Greeks as being very unsophisticated and primitive, but then when you start to read what ancient philosophers wrote you think "Wow, these guys really had things figured out, maybe better than we do now." I kind of feel the same way comparing modern GUI applications to ancient editors like ed.
Re: Use Vim Inside a Unix Pipe Like Sed or AWK
#26Re: Use Vim Inside a Unix Pipe Like Sed or AWK
#27Why is this article talking about idempotence? I don't see why that matters in the slightest for a unix pipe. Idempotence only matters if you're going to take the output of the pipe and run it back through the pipe again. There's a bit later on about idempotence and newlines, but I don't see what that has to do with idempotence. Vim will append a trailing newline if the file doesn't have one, sure, but if I pass the…
That bugged me too, although it was such a fun article I didn't want to complain. :-) What he really means is that his first snippet is the identity function. Like x*1=x or x+0=x. Whatever it gets, it passes along unmodified. I think it's actually kind of nice that he started with that. Sometimes it is not easy to figure out how to do, for instance with XLST.....
Re: Use Vim Inside a Unix Pipe Like Sed or AWK
#28Why is this article talking about idempotence? I don't see why that matters in the slightest for a unix pipe. Idempotence only matters if you're going to take the output of the pipe and run it back through the pipe again. There's a bit later on about idempotence and newlines, but I don't see what that has to do with idempotence. Vim will append a trailing newline if the file doesn't have one, sure, but if I pass the…
Re: Use Vim Inside a Unix Pipe Like Sed or AWK
#29Earlier quoted context omitted.
It's common for people today to think of ancient Greeks as being very unsophisticated and primitive, but then when you start to read what ancient philosophers wrote you think "Wow, these guys really had things figured out, maybe better than we do now." I kind of feel the same way comparing modern GUI applications to ancient editors like ed.
Which philosophers? The only one I've read in any depth is Aristotle, and while he is clearly very smart, I agreed with essentially none of it.
Re: Use Vim Inside a Unix Pipe Like Sed or AWK
#30Yikes, we can shorten that a bit. :-) function vimify() { (vim - -esbnN -c $@ -c 'w!/dev/fd/3|q!' >/dev/null) 3>&1 } $ echo ' Change Me ' | vimify 'norm vitxiOK I Will' (Don't forget '-c' if you have more than one transform.)
And further shorten that to echo ' Change Me ' | vimify 'norm vitcOK I Will'
echo 'Change Me' | vimify 'norm citOK I Will'