mzlogin / vim-markdown-toc

A vim 7.4+ plugin to generate table of contents for Markdown files.
http://www.vim.org/scripts/script.php?script_id=5460
MIT License
613 stars 59 forks source link

please add a new feature of updating existing toc #6

Closed hitzhangjie closed 8 years ago

hitzhangjie commented 8 years ago

First of all, thanks for your good work, it's very convenient to generate toc now. If you add a new feature like updating existing toc when triggering some hotkeys, it would be more useful. Is it right? I have no vim script programming experience, but I think this is a good idea for some document which contains a long table of contents. If you add a updating-toc feature, we don't have to delete existing toc again. And I think inserting toc before the document is finished is useful too, because it can help us navigate the document. So I think add a updating-toc feature is very useful. Thanks!

hitzhangjie commented 8 years ago

I have another question, 'toc' generated by your plugin, I cannot used it for navigate in documents, I used 'instant-markdown' for realtime preview. Do they the two plugins conflict with each other?

mzlogin commented 8 years ago

@hitzhangjie For your second question, it seems 'instant-markdown' use CommonMark as its Markdown parser, CommonMark does not add anchor to headings automatic default, and TOC link relyon this feature. Maybe you can find some options in these plugins to turn on it.

Unfortunately, different Markdown parser generate different anchor link for headlings, my current work is for GFM and Redcarpet, under CommonMark is untested.

At company I'm using Windows, and 'instant-markdown' doesn't support Windows official, so I cannot test the situation you said now. If you find the realtime preview page's headings have anchor with them, could you provider a demo generated html file to me for analyze? Thanks.

mzlogin commented 8 years ago

@hitzhangjie Updating existing toc is a good idea, I'll work on it when I got some free time.

sunaku commented 8 years ago

:neckbeard: Here is how I do this from Vim's command mode:

:/<!-- vim-markdown-toc \w\+ -->/,/<!-- vim-markdown-toc -->/d|execute 'normal! k'|GenTocGFM

You can replace GenTocGFM with GenTocRedcarpet as the last word of the command line too.

sunaku commented 8 years ago

Oops, this plugin already provides a :UpdateToc command. :santa: Shouldn't this issue be closed then? :closed_book:

mzlogin commented 8 years ago

@sunaku Yeah, I updated the code yesterday to add :UpdateToc command and a feature of auto update toc on save, but have not update the README doc yet. Sorry about that, I'll do it soon. Your command mode command above is very concisely, thanks.

@hitzhangjie You can use :UpdateToc command to update existing toc generated by this plugin now, and by default, the toc will auto update when save, you also can add let g:vmt_auto_update_on_save = 0 to your vimrc file to close this feature.

sunaku commented 8 years ago

Awesome! :sparkles: Auto-update on save sounds great! :+1: Thanks @mzlogin. :santa: