Search code examples
vimmarkdown

Is there a Vim plugin for previewing markdown files?


I love the marked and Mou editor which have the great capability to preview the rendering results on the fly. So I'm wondering, is there a way to do the same thing in Vim?


Solution

  • I recently found a Chrome extension that makes Chrome able to properly open and display markdown files: Markdown preview (no longer available, you can use Markdown Preview Plus now).

    Then it was just a matter of mapping a key in Vim to open the file with Chrome. Mine looks like this:

    " Open markdown files with Chrome.
    autocmd BufEnter *.md exe 'noremap <F5> :!start C:\Users\tomas\AppData\Local\Google\Chrome\Application\chrome.exe %:p<CR>'
    

    This command would have to be edited, of course, if your files don't have the ".md" extension, you want your mapping on a different key or if Chrome is located at a different location.

    Now whenever I'm editing a ".md" file I can hit <F5> to open the file in Chrome. A perfect solution would be to get Chrome to auto reload every few seconds, but I can't seem to find an such an extension that works for local files.


    Pros:

    • The ability to hit a button to preview your markdown file, without the need for any running servers or special code.
    • Works on all platforms that supports Vim and Chrome - which pretty much covers all platforms.

    Cons:

    • No auto-refresh, you have to hit <F5> every time you want to preview the file.
    • No Github-flavoured markdown.