vim-gfm-syntax


Ⅰ. 插件描述

GitHub Flavored Markdown syntax highlight extension for Vim

Ⅱ. 基本信息

创建日期:  2016-09-06
使用用户:  84
Github星:  85
插件作者:  Linda_pp

Ⅲ. 安装方法

使用Vundle管理器安装

在你的.vimrc下添加:
Plugin 'rhysd/vim-gfm-syntax'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall

对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。

使用NeoBundle管理器安装

在你的.vimrc下添加:
NeoBundle 'rhysd/vim-gfm-syntax'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall

使用VimPlug管理器安装

在你的.vimrc下添加:
Plug 'rhysd/vim-gfm-syntax'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall

使用Pathogen管理器安装

在终端中运行以下命令:
cd ~/.vim/bundle
git clone https://github.com/rhysd/vim-gfm-syntax

Ⅳ. 文档说明

GitHub Flavored Markdown Syntax Extension for Vim

Build Status

This Vim plugin provides extra syntax highlight for GitHub Flavored Markdown. GitHub adds their extra features to Markdown. This plugin fills the gap between normal Markdown and GitHub Flavored Markdown.

Supports for below syntax are added:

NameExample
Inline codecode
Mentions@rhysd
Issue number#123
Emoji:dog:
Check box- [x]
TableThis!

And it also supports concealing emoji characters.

Screenshot

BeforeAfter
![before][]![after][]

Usage

By default, this plugin is enabled for all markdown filetype files.

If you want to enable these extra syntax highlights in specific file, you can use g:gfm_syntax_enable_filetypes and sub filetypes.

Example: Only README.md enables extra highlight.

let g:gfm_syntax_enable_always = 0
let g:gfm_syntax_enable_filetypes = ['markdown.gfm']
autocmd BufRead,BufNew,BufNewFile README.md setlocal ft=markdown.gfm

If you want to highlight inner code block, standard syntax highlight support for Markdown already supports it.

let g:markdown_fenced_languages = ['cpp', 'ruby', 'json']

In above Example, C++, Ruby and JSON code blocks will be highlighted with their syntax highlight. Please note that enabling so many filetypes for code block may cause performance issue on highlighting.

If you want to support specific feature of GFM, you can control them to be highlighted by some variables.

VariableDescription
g:gfm_syntax_highlight_inline_codeIf 0, inline codes won't be highlighted.
g:gfm_syntax_highlight_mentionIf 0, mentions won't be highlighted.
g:gfm_syntax_highlight_strikethroughIf 0, strikethrough won't be highlighted.
g:gfm_syntax_highlight_emojiIf 0, emojis won't be highlighted.
g:gfm_syntax_highlight_tableIf 0, tables won't be highlighted.
g:gfm_syntax_highlight_issue_numberIf 0, issue number won't be highlighted
g:gfm_syntax_highlight_checkboxIf 0, check box won't be highlighted

If you want to use your favorite colors for syntax highlights, you can override highlight definitions. Below configration is an example where inline code will be highlighted with CursorLine highlight.

autocmd ColorScheme * highlight link githubFlavoredMarkdownCode CursorLine

githubFlavoredMarkdownCode is a highlight rule for inline code. For other rules, please see after/syntax/markdown/gfm.vim. There are so many colorschemes for Vim. One syntax file can't consider all of them. If you feel some highlighting is not good, please customize by yourself.

Note: Standard markdown syntax highlight offers markdownCode to highlight inline codes, but they also highlight code blocks. githubFlavoredMarkdownCode only highlights inline codes.

Emoji Concealing

screenshot

This plugin also supports concealing emojis using Vim's 'conceal' feature. When g:gfm_syntax_emoji_conceal is set to 1, emojis such as :dog: in will be displayed as real emoji like :dog:. Original text (:dog:) remains as is. Concealing happens only in non-current lines.

What is the Difference from vim-flavored-markdown?

vim-flavored-markdown was created for the same purpose as this plugin, and it works well.
But it does not match to my usecase in terms of below points.

  • vim-flavored-markdown introduces new filetype ghmarkdown.
    This is useful if you want to distinguish Markdown and GFM.

Otherwise, it kills original markdown filetype.
It means that many other plugins for markdown filetype are killed as well.

  • Because vim-flavored-markdown is a fork of old version of vim-markdown, it lacks some improvements (e.g. code block highlight).
  • vim-gfm-syntax supports more GFM syntax (e.g. checkbox), well-tested (with themis.vim), customizable (you can choose which syntax should be highlighted).

License

This plugin is distributed under the MIT License.

添加新评论