jsit / vim-markdown

Markdown for Vim: a complete environment to create Markdown files with a syntax highlight that don't sucks!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Markdown for Vim

A complete environment to create Markdown files with a syntax highlight that don't sucks!

Features

  • Strong support for the Markdown flavor implemented by Github: what you see in Vim is what you get on Github
  • Complete syntax implementation: supports even proper nesting of all elements in list items, this is the only plugin that is able to do that (and I believe it since it took me a while to make it right)
    • A simple example rendered with this plugin. Headers and the fenced code block in list items are correctly highlighted VimMarkdownRendering
    • The same example rendered with the most popular Markdown plugins for Vim VimMarkdownRenderingComparison1 VimMarkdownRenderingComparison2
  • Code blocks and pieces of Markdown of the current file could be edited in a separate buffer and synchronized back when you finished
    • Inside a ruby fenced code block with <Leader>e opens a temporary buffer with the right file type
    • Then select a range in visual mode and with <Leader>e opens a temporary buffer with file type markdown I call it Focus Mode because you can edit a portion of a Markdown file in isolation
    • At last, on an empty line, with <Leader>e asks for a file type and then opens a temporary buffer with that file type
    • You see that when you leave the temporary buffer the content syncs back to the main file EditCodeBlock
  • Folding for: headers, code blocks, html blocks and lists
  • Format tables automatically (require Tabular plugin)
  • Automatically detects Jekyll files and adds support for Liquid template engine
  • This is a work in progress, more goodies and improvements are coming (see TODO), stay tuned

Why?

I wanted a strong support for the Markdown flavor implemented by Github, I wanted a syntax highlight that would mirror the result I would find later on Github, I wanted a syntax highlight that would not break easily, I wanted a syntax highlight that I could rely on (aka rapid feedback), I wanted something more that a mere syntax highlight. The Markdown Syntax unfortunately it's so loosely defined that there are flavors of Markdown that are subtly incompatible from each other, the Markdown supported by Github is one of them.

Installation

If you use Vundle, add the following line to your ~/.vimrc:

Bundle 'gabrielelana/vim-markdown'

And then execute the following command in your shell:

$ vim +'BundleInstall! vim-markdown' +qall

If you use Pathogen, execute the following in your shell:

$ cd ~/.vim/bundle
$ git clone https://github.com/gabrielelana/vim-markdown.git

If you are not using any package manager, download the tarball and do this:

$ cp vim-markdown-master.tar.gz ~/.vim
$ cd ~/.vim
$ tar --strip-components=1 --overwrite -zxf vim-markdown-master.tar.gz
$ rm vim-markdown-master.tar.gz

Self-Promotion

If you like this plugin, then consider to:

Documentation

I would use this section until I have a proper documentation

Configuration

  • let g:markdown_include_jekyll_support = 1 to load support to Jekyll files (default: 1)
  • let g:markdown_enable_folding = 1 to use the fold expression markdown#FoldLevelOfLine to fold markdown files, this is disabled by default because it's a huge performance hit even when folding is disabled with nofoldenable option (default: 0)
  • let g:markdown_enable_mappings = 1 to load default leader mappings (default: 1)
    • let g:markdown_enable_insert_mode_mappings = 1 to load also insert mode leader mappings (default: 0)

Default Mappings

All default mappings are local to markdown buffers

  • <Space> (NORMAL_MODE) switch status of things:
    • A list item * item becomes a check list item * [ ] item
    • A check list item * [ ] item becomes a checked list item * [x] item
    • A checked list item * [x] item becomes a list item * item
  • <Leader>ft (NORMAL_MODE, INSERT_MODE) format the current table
  • <Leader>e (NORMAL_MODE, VISUAL_MODE, INSERT_MODE) :MarkdownEditCodeBlock edit the current code block in another buffer with a guessed file type. The guess is based on the start of the range for VISUAL_MODE. If it's not possibile to guess (you are not in a recognizable code block like a fenced code block) then the default is markdown. If it's not possibile to guess and the current range is a single line and the line is empty then a new code block is created. It's asked to the user the file type of the new code block. The default file type is markdown.

Motions

  • ]] start of the next header
  • [[ start of the previous header

While Editing in Insert Mode

  • | in a table triggers the format command
  • <Tab>/<S-Tab> on a list item it will indent/unindent the item
  • <Tab>/<S-Tab> on a blockquote it will increase/decrease the quote level
  • <Enter> on a list item with no text in it (freshly created) it will delete everything till the column 0

Development

Resources

Syntax Specs

Testing syntax highlight could be tricky, here I use the golden master patter to at least avoid regressions, this is how it works: in ./rspec/features you will find a bunch of *.md files, one for each syntactic element supported, for each of those files there's an html file, this file is created with the :TOhtml command and it's the reference (aka golden master) of the syntax highlight of the original file. Running rspec you are comparing the current syntax highlight of all the feature's file with the reference syntax highlight. If looking at some of the feature's file you see something wrong you can fix it and after regenerate the golden master files with GENERATE_GOLDEN_MASTER=1 rspec

Known Bugs

  • formatlistpat doesn't work for ordered lists
  • formatoptions thinks that * in horizontal rules are list items
## TODO * Kramdown Syntax * Block Inline Attributes * Span Inline Attributes * Fenced Code Blocks with Inline Attributes * Definition Lists * Tables * Math Blocks * Footnotes * Abbreviations * End of Block Marker * Code Blocks * Edit html code block * Edit jekyll front matter code block * Explain in this file why I chose to avoid to highlight nested block elements * Task Lists (GFM) * Command to check/uncheck task with relative mappings in command/insert/visual mode * Command to turn list items in task items with relative mappings in command/insert/visual mode * Tables (GFM) * Auto formatting tables if Tabular plugin is installed * Emoji (GFM) * Start completion when hitting `:` in insert mode only if preceded by empty spaces or is the beginning of the line * Remove duplication between syntax keywords and dictionary completion * More `iabbr` * Lists * `i_` on a list item with no text in it (freshly created) it will delete everything till the column 0 * `` on a list item it will swap it with the item above (if it exists) * `` on a list item it will swap it with the item below (if it exists) * `>` and `<` should properly indent/unindent list items * `i_` and `i_` should properly indent/unindent list items and quote lines * Define custom text objects for: * List items * Check list items * Paragraph * Start of the next paragraph `}` * Start of the previous paragraph `{` * Other inline elements * Folding * Fold HTML blocks * Always consider the first non space character of the line when check for syntax group * Always use `synstack` to check the syntax group of a position * Write specs for the whole thing * Support `foldtext` option

About

Markdown for Vim: a complete environment to create Markdown files with a syntax highlight that don't sucks!

License:MIT License