Hacker News new | ask | show | jobs
by mg 842 days ago
Is there a benefit over

    command | vim -
?

I love doing that, because then I get all the power of Vim to look at the output. Search, regex search, sorting, bookmarks, counting, macros ...

I started to write output that is indented, so I can use Vim's folding to comfortably look at complex data.

For example if you have entries like this:

    2023-04-12 17:22 Sighted and UFO
        Location: 27.1742424 12.137234
        Temperature: 24°C
        Observer: Joe
        Actually it turned out to be a dove.
And you press zM in Vim, they all turn into:

    2023-04-12 17:22 Sighted and UFO
        + 4 lines
So you have a nice overview and can open individual entries by putting the curser on them and hit zo.

And while folded, you still have all the power of Vim to search within them. Regex search. Count by any measure you like etc etc. Actually, you can do anything, as Vim allows you to execute arbitrary vim commands, vim macros or shell commands on your buffer.

Wanna know how many doves typically get mistaken for UFOs around New York grouped by month? Write a script for it and it will be forever at your fingertips.

1 comments

I think this is more designed for streamed output rather than viewing files. Vim doesn't seem to support that, in fact it just says "Vim: Reading from stdin..." forever.
Hmm.. I guess you could write a little script (2 lines?), let's call it "vimlive" which reads from stdin, streams to a temp file and opens that temp file in vim.

Then with:

    command | vimlive
You get vim with the current state of the data and you can update it with :e
You can have vim constantly refresh a buffer if it's modified externally, like this turns your buffer into a kinda-sorta-version of `tail -f`:

    :set autoread | au CursorHold * checktime | call feedkeys("G")
So if it's already a file, just open it with vim; if it's a STDOUT/STDERR stream, redirect/`tee` to a file and open that.
Also it’s not as snappy when you cross the 1GB limit, although it does work, mostly.
With a quick look at the code I'm pretty sure this WebUI also wouldn't be snappy along before that.
try

    vim filename 
lmao