Use Vim Inside a Unix Pipe Like Sed or AWK
blog.robertelder.org
blog.robertelder.org
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/diffutils/manual/html_node/ed-Sc...
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.
There's another related lesson there that progress, like evolution, is progress in a certain direction. No one said that direction is whatever you call "good" at the moment.
... and some evidence supports they were smarter...
http://www.huffingtonpost.com/2013/05/22/people-getting-dumb...
Obviously there is some interplay with the fact that we develop new mental models and thinking tools to augment intelligence.
Also immersion as children in highly abstract ways of thinking further augments/multiplies raw intelligence (most convincing explanation to the Flynn effect imo).
I've lost the link, but there was an excellent article I read related to the amazing Otzi discovery (https://en.wikipedia.org/wiki/%C3%96tzi) describing how adults of that era (modern humans, primitive societies) would likely have been terrifying to us now in just how much they outclassed us in raw strength, intelligence and stamina. We would be relying a lot on the benefits of childhood nutrition and education to feel superior. This isn't completely convincing, there are a lot of factors in play, but those levels of brutal competition and danger would have a profound effect, especially epigenetically.
My mind was constantly being blown in that class.
And the great error handling when it doesn't know what you just told it to do. ?
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 ...
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 $EDITORI should probably let dvtm fall back to vipe if it is installed. Also I will have to check whether there is an easy fix to make vipe+vis work.
I used to have blinking text for the email signups at the bottom, but I got rid of it since it didn't have a huge effect (I think it only doubled the conversion rate). I have learned that some people really hate blinking text.
Just an FYI :)
I can think of a few places where there would probably be circular object references, so that's probably where the memory leaks come from.
Thanks for the feedback :)
Everything in the linked article is easy to read on my crummy laptop screen. (Its screen makes seeing too-low-contrast color changes [0] rather difficult. The fact that all of your site is legible is a strong indicator that your contrast and color scheme choices are perfectly adequate ones.)
In short, don't change anything about the layout, unless you are really motivated to do so. You've made good choices!
[0] Such as -2 or -3 and below comments on HN.
I can't view elements from mobile, but the results look good. Layout is comfortable, good margins, well-differentiated bits, and all without being distracting.
I've got a general set of tips most of which you can likely ignore. Check that you're using em/rem rather than px or pt for font sizes: https://www.reddit.com/r/dredmorbius/comments/29eqrk/web_des...
function vimify() {
(vim - -esbnN -c $@ -c 'w!/dev/fd/3|q!' >/dev/null) 3>&1
}
$ echo '<h1>Change Me</h1>' | vimify 'norm vitxiOK I Will'
(Don't forget '-c' if you have more than one transform.)echo '<h1>Change Me</h1>' | vimify 'norm vitcOK I Will'
echo '<h1>Change Me</h1>' | vimify 'norm citOK I Will'
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 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?
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.....
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.Indeed, why use visual anything in a pipe :D?
diff file1 file2 | vim -
Gives you the diff but colorized with Vim. Handy little trick. vim -d file1 file2.This is far from practical to use on a day to day basis. It'd make my eyes bleed if some coworker used this anywhere.
Why not just pickup a scripting language like perk or Python. Use awk or sed. They're available everywhere.
[1]: Think SQL injection but with vim commands.
You can try my pmacs script to get something sort-of-like: https://github.com/tom-seddon/bin/blob/master/pmacs.py (not productized, and some self-assembly may be required - should work out of the box on Linux, though, and probably OS X too)
Works pretty well, though only at the end of a pipeline. (It could probably be extended to work mid-pipeline though; you can get emacsclient to block until the file's buffer is closed in emacs - this is what the "-n" switch inhibits - giving the script a chance to wait, load the (presumably modified) file and print it to stdout.)