preservim / vim-markdown

Markdown Vim Mode
4.68k stars 521 forks source link

Entering multiple markdown buffers gets exponentially slower #417

Open lytedev opened 5 years ago

lytedev commented 5 years ago

I'm seeing this issue when I open multiple markdown files, the Nth time I enter a ft=markdown buffer, I see N^2-ish load times. I'm using Neovim 0.4.0 beta and a handful of other plugins, but commenting vim-polyglot (or vim-markdown) out fixes the slowness.

You can see what I'm seeing by doing this:

mkdir -p /tmp/mds/
cd /tmp/mds/
seq 20 | sed 's/$/.md/' | xargs touch
nvim ./*

And then flipping through the buffers using :bnext or whatever you prefer. As you flip through more and more buffers, you will notice they start to open slower... and slower... and SLOWER.

Refs

https://github.com/sheerun/vim-polyglot/issues/290

sheerun commented 4 years ago

The slowdown seems to be because of after/ftplugin/markdown.vim file

For now I'm going to remove it from being imported to vim-polyglot

lytedev commented 4 years ago

@sheerun Thanks for looking into this! However, after updating...:

$ git --no-pager --git-dir ~/.config/nvim/bundle/vim-polyglot/.git log -1 --oneline
e8454d6 (HEAD -> master, tag: v4.2.0, origin/master, origin/HEAD) Fix performance issue with markdown highlighting

... I'm still having my problem, but I realize my original comment did not capture it well. I updated it adding this bit:

And then flipping through the buffers using :bnext or whatever you prefer. As you flip through more and more buffers, you will notice they start to open slower... and slower... and SLOWER.

Please let me know whether or not you can duplicate! Thank you.

alancaldas84 commented 3 years ago

One solution is to use builtin vim folder configured for markdown. https://stackoverflow.com/questions/3828606/vim-markdown-folding

function! MarkdownLevel() if getline(v:lnum) =~ '^# .$' return ">1" endif if getline(v:lnum) =~ '^## .$' return ">2" endif if getline(v:lnum) =~ '^### .$' return ">3" endif if getline(v:lnum) =~ '^#### .$' return ">4" endif if getline(v:lnum) =~ '^##### .$' return ">5" endif if getline(v:lnum) =~ '^###### .$' return ">6" endif return "=" endfunction au BufEnter .md setlocal foldexpr=MarkdownLevel()
au BufEnter
.md setlocal foldmethod=expr