Description
When using Markdown folding in Vim (e.g., foldmethod=expr with MarkdownFold() or a plugin like vim-markdown), lines starting with # inside fenced code blocks are incorrectly recognized as Markdown headings. This causes wrong fold levels when pressing zm or zM.
Minimal reproduction
Create test.md:
Steps to reproduce
test.md in Vim (≥ 9.1.1230).:setlocal foldmethod=expr :setlocal foldexpr=MarkdownFold()
zM (close all folds).# This is a Python comment... creates an extra fold.Actual behavior
Comments inside code blocks are treated as headings, producing incorrect folds.
Only genuine Markdown headings (outside code blocks) should affect folding. Lines starting with # inside fenced code blocks must be ignored.
Why this matters
The built-in helptoc package (issue #17699, fixed in 9.1.1533) already handles a similar problem correctly. The same logic should apply to Markdown folding.
Suggested fix
The foldexpr should detect whether the cursor is inside a fenced code block (by checking syntax regions or tracking fences) and skip those lines.
9.2.0735
windows 10 and 11
windows terminal
gvim or terminal vim
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()
@tpope is the maintainer of vim-markdown. So I suggest you move this issue to https://github.com/tpope/vim-markdown/.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()