A vim 7.4+ plugin to generate table of contents for Markdown files.
-
Generate table of contents for Markdown files.
Supported Markdown parsers:
- GFM (GitHub Flavored Markdown)
- GitLab
- Redcarpet
-
Update existing table of contents.
-
Auto update existing table of contents on save.
Note: This plugin only works in Markdown files, that usually have a .[md|mdown|mkd|mkdn|markdown|mdwn|mdx] suffix. To check file type, please run :set ft, Markdown files will echo filetype=markdown.
Suggest to manage your vim plugins via vim-plug or Vundle, so you can install it simply three steps:
-
add the following line to your vimrc file
Plug 'mzlogin/vim-markdown-toc' -
:so $MYVIMRC -
:PlugInstall
-
add the following line to your vimrc file
Plugin 'mzlogin/vim-markdown-toc' -
:so $MYVIMRC -
:PluginInstall
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.
-
:GenTocGitLabGenerate table of contents in GitLab link style.
This command is suitable for GitLab repository and wiki.
-
:GenTocMarkedGenerate table of contents for iamcco/markdown-preview.vim which use Marked 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.
:RemoveToc command will do this for you, just remember keep insert fence option by default.
You can use the :TocGoto command to jump to the heading under the cursor.
-
g:vmt_auto_update_on_savedefault:
1This 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:
0By 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 contents on save and
:UpdateToccommand. When you want to update toc, you need to remove existing toc manually and rerun:GenTocXXXcommands. -
g:vmt_fence_textdefault:
vim-markdown-tocInner text of the fence marker for the table of contents, see
g:vmt_dont_insert_fence. -
g:vmt_fence_closing_textdefault:
g:vmt_fence_textInner text of the closing fence marker. E.g., you could
let g:vmt_fence_text = 'TOC'andlet g:vmt_fence_closing_text = '/TOC'to get<!-- TOC --> [TOC] <!-- /TOC --> -
g:vmt_fence_hidden_markdown_styledefault:
''By default, vim-markdown-toc will add the markdown style into the fence of the text for the table of contents. You can avoid this and set a default markdown style with
g:vmt_fence_hidden_markdown_stylethat is applied if a fence is found containing theg:vmt_fence_textwithout any markdown style. Obviously,g:vmt_fence_hidden_markdown_stylehas to be supported, i.e. currently one of['GFM', 'Redcarpet', 'GitLab', 'Marked']. -
g:vmt_cycle_list_item_markersdefault:
0By default,
*is used to denote every level of a list:* [Level 1](#level-1) * [Level 1-1](#level-1-1) * [Level 1-2](#level-1-2) * [Level 1-2-1](#level-1-2-1) * [Level 2](level-2)If you set:
let g:vmt_cycle_list_item_markers = 1
every level will instead cycle between the valid list item markers
*,-and+:* [Level 1](#level-1) - [Level 1-1](#level-1-1) - [Level 1-2](#level-1-2) + [Level 1-2-1](#level-1-2-1) * [Level 2](level-2)This renders the same according to Markdown rules, but might appeal to those who care about readability of the source.
-
g:vmt_list_item_chardefault:
*The list item marker, it can be
*,-or+. -
g:vmt_include_headings_beforedefault:
0Include headings before the position you are inserting Table of Contents.
-
g:vmt_list_indent_textdefault:
''The indent text of list item. By default, if
expandtabis set, it will beshiftwidth([2, 5]) number of space, otherwise it will be\t. If you set this option, it will override the default behavior. -
g:vmt_linkdefault:
1Whether to generate link for headings.
-
g:vmt_min_leveldefault:
1The minimum level of headings to be included in the table of contents.
-
g:vmt_max_leveldefault:
6The maximum level of headings to be included in the table of contents.
-
g:vmt_list_flag_min_widthno default value
The minimum width of the list flag, fill with spaces if necessary.

