This 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…
Use Vim Inside a Unix Pipe Like Sed or AWK
11–20 of 49 posts
Re: Use Vim Inside a Unix Pipe Like Sed or AWK
#12Yikes, 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.)
echo 'Change Me' | vimify 'norm vitcOK I Will'
Re: Use Vim Inside a Unix Pipe Like Sed or AWK
#13Indeed, why use visual anything in a pipe :D?
Re: Use Vim Inside a Unix Pipe Like Sed or AWK
#14Yikes, 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.)
Re: Use Vim Inside a Unix Pipe Like Sed or AWK
#15I 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.
vim -d file1 file2.Re: Use Vim Inside a Unix Pipe Like Sed or AWK
#16Why type vitxi (visual inner tag delete insert), when cit (change inner tag) will do? Indeed, why use visual anything in a pipe :D?
Re: Use Vim Inside a Unix Pipe Like Sed or AWK
#17 printf "foo\nbar\nbaz\n" | vis - | sort
dvtm uses this mechanism to implement its copy mode.I also recently integrated sam's structural regular expression based command language into the editor. This might be useful for people who want the power of stream editors but with instant visual feedback.
However keep in mind that this feature is relatively new thus likely still contains some bugs ...
Re: Use Vim Inside a Unix Pipe Like Sed or AWK
#18Vim is actually a relatively bad filter (some reasons are mentioned in the caveats section of the article). I explicitly designed my vis editor[1] in such a way that it can be used as an interactive filter. The following works as expected, use :wq to write to stdout: printf "foo\nbar\nbaz\n" | vis - | sort dvtm uses this mechanism to implement its copy mode. I also recently integrated sam's structural regular express…
You can do this with any other editor using "vipe" from "moreutils" package. It just opens $EDITOR with stdin input (put to a tempfile) and then reads the tempfile and dumps it in stdout.
printf "foo\nbar\nbaz\n" | vipe - | sort # invokes $EDITORRe: Use Vim Inside a Unix Pipe Like Sed or AWK
#19This 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.
Especially as a sysadmin, I spend so much time in a ssh cli, that part of my reasoning was "I want to be able to do all my normal tasks without the gui." Gmail, news, and rss in gnus, irc in erc, org-mode (loving export to latex for reports), eww for browsing, and who knows whats next. Elixir and go modes are improving too, and my general productivity due to staying mostly inside a single ecosystem has really improved.
Another reason I have done this though, is I feel like it's less about gui vs text, and much more about FOSS vs proprietary. In a few years when everyone has an iBrain with Apple (NSA) inside, I intend to have a MEmacs brain that I have control over.
I think RMS will be vindicated in history as a man far ahead of his time.
Re: Use Vim Inside a Unix Pipe Like Sed or AWK
#20There'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 output back through Vim again, it won't append another trailing newline, it'll just preserve the existing one, so if the vim command you run is idempotent then the whole thing will still be idempotent.
I'm guessing here that the author is simply confused about what idempotence means. Because of the newline bit, I'm going to guess that what the author means by "idempotence" is "any text that the vim filter isn't supposed to modify will be left exactly as found in the input", but that's not what idempotence is, and I'd also say that that property is pretty much a given for any kind of text transformation used in a pipe, because if it doesn't hold then why are you even using that tool?