Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete part of document when folded on save #39

Open
powerman opened this issue Nov 28, 2017 · 6 comments
Open

Delete part of document when folded on save #39

powerman opened this issue Nov 28, 2017 · 6 comments
Labels

Comments

@powerman
Copy link
Contributor

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
@mzlogin
Copy link
Owner

mzlogin commented Nov 29, 2017

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

@powerman
Copy link
Contributor Author

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.

@mzlogin mzlogin added the bug label Nov 29, 2017
@mzlogin
Copy link
Owner

mzlogin commented Nov 29, 2017

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
Copy link
Owner

mzlogin commented Nov 30, 2017

execute l:beginLineNumber. "," . l:endLineNumber. "delete_"

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?

@powerman
Copy link
Contributor Author

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.

@rnmhdn
Copy link

rnmhdn commented Jul 15, 2019

This plugin still has this issue... and it fucked up all my code ☠️!
It's really a great plugin, pitty it doesn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants