Open yous opened 5 years ago
I'm seeing this as well. For me, diffs are completely broken for markdown files when this plugin is active. i.e. [c
and ]c
don't work either. I'm working around it by not activating the plugin if started in diff mode.
I'm suffering from this, too.
Setting below in .vimrc
,
the vim-markdown
folding is suppressed to work only at opening file, at least
(Instead of vim-markdown
auto setting, set folding settings by oneself).
Plugin 'plasticboy/vim-markdown'
let g:vim_markdown_folding_disabled = 1
autocmd BufNewFile,BufRead *.md setlocal foldmethod=expr foldexpr=Foldexpr_markdown(v:lnum)
So I think checking if the buffer is diff or not (using &diff) would be appropriate.
This patch may work:
diff --git a/after/ftplugin/markdown.vim b/after/ftplugin/markdown.vim
index 8be6ff9..9840217 100644
--- a/after/ftplugin/markdown.vim
+++ b/after/ftplugin/markdown.vim
@@ -177,8 +177,12 @@ function! s:MarkdownSetupFolding()
setlocal foldtext=Foldtext_markdown()
endif
endif
- setlocal foldexpr=Foldexpr_markdown(v:lnum)
- setlocal foldmethod=expr
+ if &foldexpr == ""
+ setlocal foldexpr=Foldexpr_markdown(v:lnum)
+ endif
+ if &foldmethod != "diff"
+ setlocal foldmethod=expr
+ endif
endif
endfunction
Besides foldmethod
, if foldexpr
is set, do not override it.
But I'm not sure whether this is a better solution. Could someone review and merge it?
Perhaps just checking foldexpr
might be fine.
Sometimes manual
folding is preferred, to add extra folding by zf
.
diff --git a/after/ftplugin/markdown.vim b/after/ftplugin/markdown.vim
index 8be6ff9..991a470 100644
--- a/after/ftplugin/markdown.vim
+++ b/after/ftplugin/markdown.vim
@@ -177,8 +177,10 @@ function! s:MarkdownSetupFolding()
setlocal foldtext=Foldtext_markdown()
endif
endif
- setlocal foldexpr=Foldexpr_markdown(v:lnum)
- setlocal foldmethod=expr
+ if &foldexpr == ""
+ setlocal foldexpr=Foldexpr_markdown(v:lnum)
+ setlocal foldmethod=expr
+ endif
endif
endfunction
This issue being left for a long time, raised a pull-request formally.
The default value of 'foldexpr'
is "0"
, so comparing against ""
would disable the entire feature.
'foldexpr' 'fde'
'foldexpr' 'fde' string (default: "0")
local to window
{not available when compiled without the +folding
or +eval features}
Oh, this was because I set foldexpr
for *.md
in .vimrc
. Got it.
Fixed.
For example, add a random line to this project's README.md and save it as README2.md:
Run
vimdiff README.md README2.md
, then one of the buffer will have weird folding:According to after/ftplugin/markdown.vim, the
s:MarkdownSetupFolding()
is called onBufWinEnter
,BufWritePost
,InsertEnter
,InsertLeave
,CursorHold
,CursorHoldI
. When Vim shows diff,'foldmethod'
is set to'diff'
, ands:MarkdownSetupFolding()
resets it. So I think checking if the buffer is diff or not (using&diff
) would be appropriate.