Pre-fold output of :r! command

10 views
Skip to first unread message

Julius Hamilton

unread,
Jul 4, 2021, 4:08:41 PM7/4/21
to vim...@googlegroups.com
I would like to print the output of a shell command - a webpage dump - into a Vim buffer, and have those lines immediately folded, rather than a second step of selecting and folding them.

The command would look something like:

:r! w3m -dump url.com FOLD

How would this be possible?

I would like to navigate my folds in an easier way than navigating to the blue line that appears, and unfolding them. Is it possible to get some kind of table of contents sidebar where you can select a fold and open or close it? In my current configuration, I don't see an indicator that a fold is on a certain line, if that fold is currently unfolded.

Thank you very much,
Julius


Suresh Govindachar

unread,
Jul 4, 2021, 4:53:18 PM7/4/21
to vim...@googlegroups.com, Julius Hamilton
On 7/4/2021 1:08 PM, Julius Hamilton wrote:
> I would like to print the output of a shell command - a webpage dump -
> into a Vim buffer, and have those lines immediately folded, rather than
> a second step of selecting and folding them.
>
> The command would look something like:
>
> :r! w3m -dump url.com <http://url.com> FOLD
>
> How would this be possible?

Tested the following for <some_command> being dir:

exec(':r !<some_command>') |normal zM

> I would like to navigate my folds in an easier way than navigating to
> the blue line that appears, and unfolding them. Is it possible to get
> some kind of table of contents sidebar

Doesn't the first line of the fold constitute a table of contents? I do
not see a blue line -- instead, I see a + in the left most column and
the rest of the line is the first line of the folded material.

> where you can select a fold and
> open or close it? In my current configuration, I don't see an indicator
> that a fold is on a certain line, if that fold is currently unfolded.

For me, I know the rules being used for creating folds. So when I see
unfolded material, I can see the rule for folding in the material and
know that the material is unfolded material. Since I can readily see
that the unfolded material is part of a fold, I do not need an
additional, superfluous indicator that the material can be folded.

Ailen Vienne Sebastian

unread,
Jul 5, 2021, 5:48:53 AM7/5/21
to vim...@googlegroups.com
Please reply to me. Please

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CAGrXgp3wif%2BEhQoowHn32C-epQF8m%3DTtqqfKK2A0tDWoB2%3DznA%40mail.gmail.com.

Christian Brabandt

unread,
Jul 5, 2021, 7:55:52 AM7/5/21
to vim...@googlegroups.com

On So, 04 Jul 2021, Julius Hamilton wrote:

> I would like to print the output of a shell command - a webpage dump - into a
> Vim buffer, and have those lines immediately folded, rather than a second step
> of selecting and folding them.
>
> The command would look something like:
>
> :r! w3m -dump url.com FOLD
>
> How would this be possible?

Perhaps like this:

:exe ":r! w3m -dump url" |'[,']fold

Unfortunately the `|` is seen as an argument to the :r! command, that's
why we have to wrap it in an `:exe "..." call and can separate the next
ex command using |, which in this case is the :fold command for the
region given by the markers '[,'], which describes the region of the
previously inserted text.

You can probably wrap this into a custom command like this:

:com -nargs=1 Dump :exe ":r! -dump <args>"|'[,']fold

(untested) and then use

:Dump <url>


>
> I would like to navigate my folds in an easier way than navigating to the blue
> line that appears, and unfolding them.

The little blue line is hard-coded I believe. But you can disable it
using :set foldcolumn=0

> Is it possible to get some kind of table
> of contents sidebar where you can select a fold and open or close it? In my
> current configuration, I don't see an indicator that a fold is on a certain
> line, if that fold is currently unfolded.

Not sure I understand what you want here.

Best,
Christian
--
Ein Idealist ist ein Mann, der aus der Tatsache, daß die Rose besser
riecht als der Kohl, darauf schließt, eine Suppe aus Rosen müsse auch
besser schmecken.
-- Ernest Hemingway

Julius Hamilton

unread,
Jul 6, 2021, 11:59:57 AM7/6/21
to vim...@googlegroups.com
Thanks very much. That works perfectly.

One tiny tweak is I would just like to be able to collapse and open a fold back and forth with ease. If I unfold that fold, I think the fold disappears. I then have to respecify the content to be folded. Or if not, I still have to put my cursor on the top line of the fold, to re-fold it.

I would prefer to just have a go to button to fold and unfold what was printed, no matter where in the document I am.

What would be the most convenient way to refold a large section of text after having unfolded it?

Thanks very much,
Julius

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.

Tim Chase

unread,
Jul 6, 2021, 12:48:58 PM7/6/21
to Julius Hamilton, vim...@googlegroups.com
On 2021-07-06 17:59, Julius Hamilton wrote:
> If I unfold that fold, I think the fold disappears. I then have to
> respecify the content to be folded. Or if not, I still have to put
> my cursor on the top line of the fold, to re-fold it.

Unless you delete the fold, it should remain even after you expand it.
You can see a visualization of your folds by setting some appropriate
value (roughly how many fold-levels you expect to nest) to
'foldcolumn' such as

:set foldcolumn=4

> I would prefer to just have a go to button to fold and unfold what
> was printed, no matter where in the document I am.

You can use

za

to toggle folds under the cursor, or

zR

to expand all folds in the entire file and

zM

to collapse all folds in the file. There's also

zX

to reset all open/closed folds so that they return to 'foldlevel'

And of course, there's

zo
zO

to expand ("open" is my mnemonic) one/all folds under the cursor and

zc
zC

to close all folds under the cursor. If you start reading around

:help zo

there are a lot of commands for opening/closing and jumping between
folds that should get you what you need.

> What would be the most convenient way to refold a large section of
> text after having unfolded it?

Usually

zC

should do this for the section containing the cursor, or

zM

for all folds everywhere.

-tim




Reply all
Reply to author
Forward
0 new messages