Wikia

Vim Tips Wiki

Quick Markdown Preview

1,623pages on
this wiki
Talk0

It just happens too often that I edit Markdown files. Even if not markdown, sometimes I convert simple text files to HTML and I use Markdown for conversion. I often use discount and pandoc as some of best Markdown tools. I also like speed, so for Markdown preview I like to use either discount or pandoc version. That is why I have created a simple key related Vim macro.

While anybody can choose any browser, I have chosen Dillo as one of fastest appearing browsers on screen. You can adapt this to use any browser by your choice

I have mapped CTRL-P for Markdown preview, but you may adapt it for any other key that you wish.

It is fairly simple, and here is the line that has to be inserted in .vimrc

map ^P :w!<CR>:w!/home/user/tmp/vim-markdown.md<CR>:!pandoc -s -f markdown -t html -o /home/user/tmp/vim-markdown.html /home/user/tmp/vim-markdown.md<CR>:!dillo /home/user/tmp/vim-markdown.html > /dev/null 2> /dev/null&<CR><CR>

You need to take care that you use correct temporary directory. You can also name your temporary file vim-markdown.md just as you like it. The file is saved under its original name before the preview, and it will not interfere with quick markdown preview.

Around Wikia's network

Random Wiki