How can I make zC fold only the current fold and the ones underneath? now it closes all outer folds.

For example, something like this will result in all brackets closing, while I would like to have only GlossList and the ones underneath folded.

  "glossary": {                                                               
    "title": "example glossary",                                            
    "GlossDiv": {                                                               
    "title": "S",                                                       
    "GlossList": { <-cursor here                                                            
       "GlossEntry": {                                                 
         "ID": "SGML",                                               
         "SortAs": "SGML",                                                     
         "GlossTerm": "Standard Generalized Markup Language",                  
         "Acronym": "SGML",                                                    
         "Abbrev": "ISO 8879:1986",                                            
         "GlossDef": {
           "para": "A meta-markup language, used to create markup languages such as DocBook.",
           "GlossSeeAlso": ["GML", "XML"]
         "GlossSee": "markup"                                                  

Atom's Vim integration works like that, but I can't get used to the editor itself.

Edit: How vim behaves zC Vim

How atom behaves (and I would like to get vim to behave) enter image description here

  • How about zc? – hgiesel Feb 5 '18 at 19:50
  • zc only closes the current fold, leaving nested ones open; i.e: if I reopen GlossList, GlossEntry will also be open. – Dumitru Feb 6 '18 at 9:08
  • How do you reopen GlossList without reopening GlossEntry if they are folded to a single line? – hgiesel Feb 6 '18 at 9:11
  • I have added an example to my post. See that vim closes the entire document, instead of just the current fold. – Dumitru Feb 6 '18 at 9:22

Seems that this would have a straightforward answer yet I'm not finding anything simple that accomplishes exactly what OP wants. OTOH, I'm not too well versed in folds! Anyways, here are some approximations. Maybe they'll be useful...

If you know the number of fold levels from the deepest point to the cursor you can do Nzm where N is an integer. With your example this would be 3zm. Open it back up with 3zr (or zr three times) Unfortunately, this starts from the deepest point in the buffer and works its way up. IOW it's not related to your cursor position!

An alternative that takes the cursor position into consideration, is to move your cursor to the deepest point of the section you want to fold, as opposed to the top of the section, and repeat zc (enter repeatedly or do Nzc with appropriate N) until you are at the point you are starting in your example.

Note: I'm using syntax folding here set fdm=syntax as opposed to indent or other method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.