• Stars
    star
    604
  • Rank 74,189 (Top 2 %)
  • Language
    Vim Script
  • License
    MIT License
  • Created almost 9 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A vim 7.4+ plugin to generate table of contents for Markdown files.

vim-markdown-toc

A vim 7.4+ plugin to generate table of contents for Markdown files.

中文版使用指南

Table of Contents

Features

  • 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.

Installation

Suggest to manage your vim plugins via vim-plug or Vundle, so you can install it simply three steps:

vim-plug

  1. add the following line to your vimrc file

    Plug 'mzlogin/vim-markdown-toc'
    
  2. :so $MYVIMRC

  3. :PlugInstall

Vundle

  1. add the following line to your vimrc file

    Plugin 'mzlogin/vim-markdown-toc'
    
  2. :so $MYVIMRC

  3. :PluginInstall

Usage

Generate table of contents

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.

  1. :GenTocGFM

    Generate 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.

  2. :GenTocRedcarpet

    Generate table of contents in Redcarpet link style.

    This command is suitable for Jekyll or anywhere else use Redcarpet as its Markdown parser.

  3. :GenTocGitLab

    Generate table of contents in GitLab link style.

    This command is suitable for GitLab repository and wiki.

  4. :GenTocMarked

    Generate 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.

Update existing table of contents

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.

Remove table of contents

:RemoveToc command will do this for you, just remember keep insert fence option by default.

Options

  1. g:vmt_auto_update_on_save

    default: 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
  2. g:vmt_dont_insert_fence

    default: 0

    By default, the :GenTocXXX commands 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 :UpdateToc command, 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 :UpdateToc command. When you want to update toc, you need to remove existing toc manually and rerun :GenTocXXX commands.

  3. g:vmt_fence_text

    default: vim-markdown-toc

    Inner text of the fence marker for the table of contents, see g:vmt_dont_insert_fence.

  4. g:vmt_fence_closing_text

    default: g:vmt_fence_text

    Inner text of the closing fence marker. E.g., you could let g:vmt_fence_text = 'TOC' and let g:vmt_fence_closing_text = '/TOC' to get

    <!-- TOC -->
    [TOC]
    <!-- /TOC -->
    
  5. g:vmt_fence_hidden_markdown_style

    default: ''

    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_style that is applied if a fence is found containing the g:vmt_fence_text without any markdown style. Obviously, g:vmt_fence_hidden_markdown_style has to be supported, i.e. currently one of ['GFM', 'Redcarpet', 'GitLab', 'Marked'].

  6. g:vmt_cycle_list_item_markers

    default: 0

    By 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.

  7. g:vmt_list_item_char

    default: *

    The list item marker, it can be *, - or +.

  8. g:vmt_include_headings_before

    default: 0

    Include headings before the position you are inserting Table of Contents.

Screenshots

References

More Repositories

1

awesome-adb

ADB Usage Complete / ADB 用法大全
11,222
star
2

mzlogin.github.io

Jekyll Themes / GitHub Pages 博客模板 / A template repository for Jekyll based blog
HTML
1,555
star
3

CleanExpert

A cleaner app for android
Java
146
star
4

markdown-intro

Markdown Intro / Markdown 简介
145
star
5

guanggoo-android

过早客第三方 Android 客户端。
Java
92
star
6

rtfsc-android

Read The F*cking Android Source Code
72
star
7

dujitang

毒鸡汤 - 静态页面版 egotong/nows
CSS
58
star
8

jekyll-theme-solid

A simple and clean jekyll theme without javascript
CSS
35
star
9

csdncommenter

自动打分评论指定 CSDN 账号内所有下载过待评论的资源。
Python
33
star
10

QRCodeScanner

A QRCode Scanner for Windows/Mac OS X/Linux in Qt.
C++
26
star
11

config-files

config files in home dir
Shell
22
star
12

project-management-notes

项目管理学习笔记与经验教训
21
star
13

common-mistakes-in-thinking

常见思维偏误
17
star
14

android-reverse-engineering

My notes for android reverse engineering learning.
14
star
15

rouge-themes

Highlight themes generated by rougify.
Python
12
star
16

android-study-guide

Android 从入门到放弃
11
star
17

kual-wifi-transfer

Kindle WiFi Transfer extension / Kindle WiFi 传书插件
Python
9
star
18

learn-android

android practices demo records
Java
8
star
19

WiFiDirect

A server and a client for WiFi Direct transmission
Java
8
star
20

kindle-paperwhite-screensavers

适用于 Kindle Paperwhite 的屏保图片。
JavaScript
7
star
21

skill-tree

期一日,汝参天。
JavaScript
7
star
22

android-ui-demos

Android UI develop practices / Custom Views
Java
6
star
23

guitar_assistant

Guitar Assistant / 吉他助手 节拍器
Dart
6
star
24

android-exceptions

崩溃与异常情景分析
6
star
25

snippets

My own snippets
Java
5
star
26

vim-i-know

关于 Vim,我知道的都在此。
5
star
27

kual-ssh-sftp-server

依赖于 KUAL 和 KOReader 的 Kindle 插件,用于在 KUAL 里直接启动 SSH & SFTP Server。
Shell
5
star
28

android-studio-settings

My Settings & Monokai theme for Android Studio 2.0+.
4
star
29

git-tutor-for-svn-user

Git tutor for SVN user / SVN 用户的 Git 指南
Shell
4
star
30

AndroidDebugHelper

A tiny tool for Android Developers
Java
4
star
31

vim-kramdown-tab

📦 A vim plugin to resolve indent issue of content nested in Markdown lists, especially for kramdown.
Vim Script
4
star
32

CVE-2021-44228-Demo

Apache Log4j2 CVE-2021-44228 RCE Demo with RMI and LDAP
Java
3
star
33

BlackHoleAnimationView

An android animation view library
Java
3
star
34

WrapContentListView

A ListView which its height can wrap content even if it is nested in a ScrollView.
Java
3
star
35

learn-spring

学习 Spring 过程中的实践代码
Java
3
star
36

patterns-and-architectures

Life is full of routines, the code is the same.
3
star
37

android-controller

Just a handle simulator to control Android on PC.
Python
3
star
38

learn-office-automation-through-examples

通过实例学办公自动化,小白适用,by Python。
Python
3
star
39

blog-comments

This repo is used to store comments of mazhuang.org
2
star
40

learn-vba-the-hard-way

Learn VBA the Hard Way / 笨方法学 VBA 办公自动化
2
star
41

time-for-windows

A command to stats program running time on Windows.
C++
2
star
42

drawio-files

Diagrams which can edit with draw.io
2
star
43

LeetCode

LeetCode Problems' Solutions
C++
2
star
44

MemIniParser

A memory ini parser
C++
2
star
45

learn-java

Java 语言、Spring 系列学习笔记
Java
2
star
46

style-guides

📖 My personal style guides.
1
star
47

awesome-fiddler

Fiddler Usage Complete / Q&A
1
star
48

kual-screensaver-sync

依赖于 KUAL 的 Kindle 插件,用于从 GitHub 同步屏保图片。
Python
1
star
49

DesignPatternDemos

design pattern study notes
C++
1
star
50

learn-ios

学习 iOS 开发
Objective-C
1
star
51

more-search-engines-for-safari

An extension to add more search engines for safari.
JavaScript
1
star
52

watch-tv

1
star
53

blog-assets

一些相对大的静态资源,如 GIF 等,不想放在博客源码里,单独拿出来放这里。
1
star