A markdown previewer using Golang mdtohtml
A small Vim plugin for previewing markdown files in a browser using the mdtohtml tool. It opens whatever browser is set as your system default. This plugin is a variation on the plugin Vim Markdown Preview.
The aim of this plugin is to be light weight with minimal dependencies. Thus, there is no polling engine or webserver involved.
- With Vundle:
- Add
Plugin 'adampresley/vim-markdown-preview-mdtohtml'
to your.vimrc
. - Launch
vim
and run:PluginInstall
- Add
- With Plug:
- Add
Plug 'adampresley/vim-markdown-preview-mdtohtml'
to your.vimrc
. - Launch
vim
and run:PlugInstall
- Add
By default, when in a .markdown
or .md
file, and Ctrl-m
is pressed, this plugin will either open a preview in your browser, or refresh your current preview.
Your cursor will remain in Vim.
This tool requires mdtohtml. To install it you must have Go installed first. Once you have Go installed execute the following on your command line:
go get -u github.com/gomarkdown/mdtohmtl
This will create the mdtohtml executable in the default Go bin folder. Ensure that folder is in your system PATH.
All options have default values and work out of the box. If you prefer to change these, just add the following lines to your .vimrc file. Note that after changing an option, you have to restart Vim for the change to take effect.
By default, this plugin maps <C-m>
(Control m) to activate the preview. To remap Control m to a different hotkey, change the binding. Don't forget to add the single quotation marks.
Default: '<C-m>'
Example: Mapping Control M.
let vim_markdown_preview_hotkey='<C-p>'
If your system does not come with see
, and you would like to use xdg-open
to view your rendered html in the browser, set the following flag:
Default: 0
Example: Use xdg-open
.
let vim_markdown_preview_mdtohtml_use_xdg_open=1
- First, this plugin renders your markdown as html and creates a temporary html file in
/tmp
. - Next, this plugin either opens the html file or refreshes the Google Chrome or Safari tab.