vim-markdown-toc icon indicating copy to clipboard operation
vim-markdown-toc copied to clipboard

Delete part of document when folded on save

Open powerman opened this issue 7 years ago • 6 comments

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

powerman avatar Nov 28 '17 22:11 powerman

Sorry but I can't find :FoldMatching command, can you tell me which plugin it comes from?

mzlogin avatar Nov 29 '17 12:11 mzlogin

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.

powerman avatar Nov 29 '17 12:11 powerman

I reproduce that, it should be a bug.

I'll try to fix it. Thanks for your report, any PR or idea is graceful.

mzlogin avatar Nov 29 '17 15:11 mzlogin

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?

mzlogin avatar Nov 30 '17 01:11 mzlogin

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.

powerman avatar Nov 30 '17 06:11 powerman

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.

rnmhdn avatar Jul 15 '19 13:07 rnmhdn