-1

I'm using vim 8.2 on Win 10. I want to enable markdown folding with the built-in markdown.vim.

But it will not work. I have tried solutions from other questions (e.g., Enable Expr Folding in Markdown and How to fold markdown using the built-in markdown mode?), but to no avail.

My vimrc contains...

let g:markdown_folding = 1
let g:markdown_fenced_languages = ['vim', 'yaml', 'python', 'bash=sh', 'sql', 'git', 'make', 'html', 'css', 'javascript', 'js=javascript', 'json=javascript', 'xml']
syntax enable
set nocompatible

My file is detected as markdown, as shown here...

:filetype returns detection:ON plugin:ON indent:ON
:set ft returns markdown
:set foldmethod? returns manual

:scriptnames output includes...

27: C:\Program Files (x86)\Vim\vim82\ftplugin\markdown.vim
30: C:\Program Files (x86)\Vim\vim82\syntax\markdown.vim

I do not have a vimwiki plugin (one user reported getting rid of vimwiki plugin solved the issue)

Yet zc, zR, zM, and zo all result in E490: No fold found, no matter where I place the cursor (on the ##, on the heading name, or inside the text associated with that heading)

Hmmm...

I just found another question regarding this topic (No folding of markdown files) which contains what seems to be a solution, but which is a bit beyond my vim skill level. Does anyone recommend I try that solution? I'd rather not unless it truly is the only solution to my problem.

Further info per comments...

:version contains +folding
:verbose set foldmethod? returns foldmethod=manual

markdown.vim contains the following if-statement..

if has("folding") && exists("g:markdown_folding")
  setlocal foldexpr=MarkdownFold()
  setlocal foldmethod=expr
  setlocal foldtext=MarkdownFoldText()
  let b:undo_ftplugin .= " foldexpr< foldmethod< foldtext<"
endif

has("folding") is true
exists("g:markdown_folding") is false

AHA!!!

.. and the reason markdown_folding was false? ...a typo in my gvimrc (!)

I fixed the typo and folding is operational!

9
  • What does :verbose set foldmethod? say? Does :version say +folding (that folding support is included)? The markdown.vim ftplugin should set foldmethod=expr, I wonder why you're not seeing that...
    – filbranden
    Aug 17 '20 at 4:10
  • 1
    Problem solved. Details in my orig post. filbranden thanks for the questions. It would have taken me a lot longer to find my typo without them. Aug 17 '20 at 5:14
  • 1
    I guess you mean exists("g:markdown_folding") right? has() checks other things... Would you mind posting a self-answer to your question? (Otherwise we can close it as a problem that can't be reproduced...)
    – filbranden
    Aug 17 '20 at 5:28
  • 1
    Yes I meant exists("g:markdown_folding"), not has("g:markdown_folding") !!! I pasted the if statement correctly but mistakenly wrote 'has' in the text below. Thanks for pointing that out. I am fixing it. Aug 21 '20 at 14:50
  • 1
    @BinaryBob I just reopened the question, so go ahead and post an answer. Edit your question to make it accurate to what your problem was, if needed. Cheers!
    – filbranden
    Aug 21 '20 at 15:09
0

This turned out to be a typo in my .gvimrc.

"WRONG .gvimrc
let g:markdownfolding = 1

.. I had omitted the underscore between 'markdown' and 'folding'. I realized this when I manually evaluated the two clauses of this if statement from markdown.vim...

if has("folding") && exists("g:markdown_folding")

the exists() was returning false, which was a big clue and led me to look at my own gvimrc and notice the missing underscore. The corrected gvimrc line looks like...

"CORRECT .gvimrc
let g:markdown_folding = 1
1
  • Please tick your question as "answered"
    – TornaxO7
    Apr 29 at 6:44

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.