0

I use Neovim without any extra Markdown plugin.

With the option let g:markdown_folding = 1 my Markdown document is automatically folded, but only the h1 headers are displayed. I'd like all the headers to be displayed.

For instance with this document

# section1

text

## sub11

other text

## sub12

some text

# section2

text

## sub21

other text

## sub22

some text

I'd like to see

# section1
## section 11
## section 12
# section 2
## section 21
## section 22

and not just

# section1
# section2

Is that possible?

2 Answers 2

1

The vim-markdown-folding plugin does exactly what I needed out of the box.

0

Not 100% what you're looking for but an easy way is to adapt the foldlevel option. See :help 'foldlevel' for more information.

Your example markdown after :set foldlevel=1:

# section1                                                                  
                                                                             
text                                                                        
                                                                            
## sub11 [4 lines]----------------------------------------------------------
## sub12 [4 lines]----------------------------------------------------------
# section2                                                                  
                                                                           
text                                                                                                                                                    
## sub21 [4 lines]----------------------------------------------------------
## sub22 [3 lines]----------------------------------------------------------

As you can see, the folds are hierarchical. To fold everything up to the next header, you would need to either use another foldmethod or change the foldexpr used for markdown.

Tested with Vim; NeoVim should behave in a similar way.

2
  • Thanks Friedrich. I could not make it work as I wanted in neovim but found vim-markdown-folding which does exactly what I need.
    – Florent2
    Commented Apr 3 at 9:20
  • 1
    Glad you found a solution that works for you. Consider posting an answer of your own for the benefit of future readers. You will be able to accept your own answer after 48 hours.
    – Friedrich
    Commented Apr 3 at 9:25

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.