3

Is there a good way to use folding with "plain text" files?

But what do I mean by "plain text"?
I'm thinking of text like it is used in human communication when no formal structure is required.

It has some ad-hoc structure, like paragraphs, indentation changes, maybe ranges of cited lines.
But with no clear rules.

It's certainly possible to use folding for this kind of text: it can be done manually.
I am looking for ways to make that easier.


One way to answer this could be to use a plugin that provides a set of support functions, used loosely together.

They could implement things like

  • handling folding for structured sections of text, while tolerating the other parts
  • check or enforce rules of some kind of minimal structure
  • support restructuring of the text


A different approach, related to the third item, would be to require to change the text to be more structured.

With this, a valid, but suboptimal solution is to require the user to reformat the text to Markdown, and then use a standard Markdown filetype plugin to handle the folding.

closed as too broad by Doorknob, Martin York, kenorb, Martin Tournoij, Rich Feb 23 '15 at 8:12

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    Welcome to Vi and Vim Stack Exchange! I'm voting to close this as Too Broad, because as it currently stands, there's no way to provide a definitive answer. We have no idea what kind of text you're working with, and "how do I fold... stuff" isn't specific enough of a question. (Of course your text has paragraphs and whatnot, but there's not a clear enough description to get an idea about what you're talking about.) Perhaps you could edit in an example of what kind of plain text you would be editing. – Doorknob Feb 22 '15 at 5:22
  • @Doorknob I described two ways of how it can be solved, does that make it more understandable? The entire point of it is to have tools that can be used on "stuff" - as long as it has partial structure. – Volker Siegel Feb 22 '15 at 7:55
  • no clear rules. -> Well, it's the nature of the computer to work by rules. You can create folds in $any file format. I do so in one of my scripts; there are also some folding functions (:help folding-functions); you can combine this to create a complex set of rules to be "smart" about what Vim should fold, I'm not sure if this will actually work very well (but it could perhaps do), but such thing is certainly not trival to do, and IMHO beyond the scope of an answer here.. – Martin Tournoij Feb 22 '15 at 16:46
  • @Carpetsmoker Oh, I would not expect the answer to implement a solution! More like pointing to existing tools or methods. I'd say your comment is almost an answer. – Volker Siegel Feb 22 '15 at 17:07
  • I agree that it's hard to answer the question "How do I make folding do the right thing for text of mixed structure?" when any two people will have differing opinions about what is right. I would suggest picking a singular simple foldmethod (indent, marker, manual) and adapting the text as you read it so that it's folded as desired. It is fairly trivial for a user to select a block of text and make a fold manually (zf) or by indenting (>) as they read. I don't understand how a script could make this simpler. – Matt Boehm Feb 23 '15 at 21:03

Browse other questions tagged or ask your own question.