vim-markdown-toc
                                
                                 vim-markdown-toc copied to clipboard
                                
                                    vim-markdown-toc copied to clipboard
                            
                            
                            
                        Delete part of document when folded on save
Looks like if TOC is inside folded block then whole block is deleted while auto-updating TOC on save and TOC is added few lines below deleted block. For example (require foldutil plugin), starting from document:
# test
<!-- vim-markdown-toc GitLab -->
* [one](#one)
* [two](#two)
    * [subtwo](#subtwo)
* [three](#three)
<!-- vim-markdown-toc -->
## one
## two
### subtwo
## three
Doing :w makes no change, but after :FoldMatching ^# -1 next :w will change document to:
## one
<!-- vim-markdown-toc GitLab -->
* [two](#two)
    * [subtwo](#subtwo)
* [three](#three)
<!-- vim-markdown-toc -->
## two
### subtwo
## three
Sorry but I can't find :FoldMatching command, can you tell me which plugin it comes from?
I've already mentioned it:
(require foldutil plugin)
http://www.vim.org/scripts/script.php?script_id=158 Probably you can make folds using any other method, this one is just more convenient for custom folding.
I reproduce that, it should be a bug.
I'll try to fix it. Thanks for your report, any PR or idea is graceful.
https://github.com/mzlogin/vim-markdown-toc/blob/98dccaebf582a4b366f1c96c9d4bc9596092c07d/ftplugin/markdown.vim#L359
did this.
ref https://www.linux.com/learn/vim-tips-folding-fun
Vim also treats a folded section of text as a single line for the purpose of deleting and yanking text. If you place the cursor on a section of folded text and use dd, it will delete the entire section, not just the first line.
Do your have any good ideas?
I suppose simulating normal editing flow should solve this. I.e. what we do if we want to delete old TOC and replace it with new one manually, and TOC is currently hidden inside some fold? Move cursor to that fold, unfold it with zo, edit as usually, fold it back with zc. So, you need to find a way to detect fold which contains TOC (manually /<!-- vim-markdown-toc \w will do the trick, but it'll also auto-unfold if it's folded, which prevent you from knowing and thus keeping current folded state) and to somehow find out is it folded now or not to restore this state later.
This plugin still has this issue... and it fucked up all my code :skull_and_crossbones:! It's really a great plugin, pitty it doesn't work.