A vim plugin to generate table of contents for Markdown files.
-
Generate table of contents for Markdown files.
Supported Markdown parsers:
- GFM (GitHub Flavored Markdown)
- Redcarpet
-
Update existing table of contents.
-
Auto update existing table of contents on save.
Suggest to manage your vim plugins via Vundle so you can install it simply three steps:
-
add the following line to your vimrc file
Plugin 'mzlogin/vim-markdown-toc' -
:so $MYVIMRC -
:PluginInstall
Installation with vim-plug is likeness.
Move the cursor to the line you want to append table of contents, then type a command below suit you. The command will generate headings after the cursor into table of contents.
-
:GenTocGFMGenerate table of contents in GFM link style.
This command is suitable for Markdown files in GitHub repositories, like
README.md, and Markdown files for GitBook. -
:GenTocRedcarpetGenerate table of contents in Redcarpet link style.
This command is suitable for Jekyll or anywhere else use Redcarpet as its Markdown parser.
You can view here to know differences between GFM and Redcarpet style toc links.
Generally you don't need to do this manually, existing table of contents will auto update on save by default.
The :UpdateToc command, which is designed to update toc manually, can only work when g:vmt_auto_update_on_save turned off, and keep insert fence.
-
g:vmt_auto_update_on_savedefault: 1
This plugin will update existing table of contents on save automatic.
You can close this feature by add the following line to your vimrc file:
let g:vmt_auto_update_on_save = 0
-
g:vmt_dont_insert_fencedefault: 0
By default, the
:GenTocXXXcommands will add<!-- vim-markdown-toc -->fence to the table of contents, it is designed for feature of auto update table of contents on save and:UpdateToccommand, it won't effect what your Markdown file looks like after parse.If you don't like this, you can remove the fence by add the following line to your vimrc file:
let g:vmt_dont_insert_fence = 1
But then you will lose the convenience of auto update tables of contens on save and
:UpdateToccommand. When you want to update toc, you need to remove existing toc manually and rerun:GenTocXXXcommands.

