0

I used :%g /{/ normal! zf% to recursively create folds in a very unusual header file which is parsed by an application. It is supposed to be manually edited but is currently +8k lines and for navigation there is only just a comment before the opening of each curly bracket.

after all folds have been created how can I open a top level fold while keeping the inner ones closed?

enter image description here

Edit: I added a screenshot of what happens when I try to open the fold. It does not open and instead it only adds a dash right next to the plus sign on the line the fold starts. The more times I do zo the more dashes appear until the deepest level fold is reached. Also navigating left, right, up or down still doesn't show whats inisde.

1
  • 1
    It would help to have a representative sample (not 8k lines!) of the file (even if not the exact file); the accepted answer suggests that you might have accidentally nested the folds, but it's hard to tell.
    – D. Ben Knoble
    Commented Jul 9 at 21:18

1 Answer 1

1
  1. Run Vim. Press F1 button.
  2. Scroll down until you see quickref hyperlink. Click to follow.
  3. Scroll down to see Q_fo folding hyperlink. Click to follow.
  4. Read until found zo open one fold under the cursor.

Upd. zo opens exactly one level of folding. If it only appears as "an extra dash" (:h v:folddashes) then the current fold has even greater :h foldlevel() than that.

Instead, creating the folds should be:

edit foobar.c
set foldmethod=manual
normal! zE
g/}/normal! zf%
3
  • for some reason doing zo doesn't open the fold in my case. It only adds one more dash immediately after the plus sign on the line where the fold starts. And of course I checked the help pages through and through before posting here. Posting here requires somewhat more effort :D
    – martin767
    Commented Jul 9 at 12:10
  • @martin767 Exactly. A question should be complete from the beginning.
    – Matt
    Commented Jul 9 at 13:06
  • alright. cool )
    – martin767
    Commented Jul 9 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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