One of the biggest advantages of using a dedicated tool for writing Markdown is that they often come with some way of previewing your text file. I kind of miss that kind of function when I’m using Vim I decided to throw together a simple vimscript that uses Pandoc to convert a Markdown file to HTML. The basic gist of it looks like this:
It sets the directory of the current open file as the root and then calls Pandoc
to do the conversion. It’s not that terribly complicated but it gets the job
done well. I also expanded upon it a bit and added another part that’ll open the
preview.html directly in the browser:
One thing that’s worth being mentioned is that the
!xdg-open part can be
!open and then you can also use it if you’re on a Mac.
In the end the whole thing looks like this:
And the mapping looks like this:
I also threw together more refined version of the whole thing in a gist on Github. You’ll obviously need to have Pandoc install on your machine in order to get it up and running.