Is there a Vim plugin for previewing markdown files? [closed]

Solution 1:

You're in luck - I've just written a vim plugin with real-time Markdown previewing. It uses github Markdown and styles too: https://github.com/suan/vim-instant-markdown

Solution 2:

I recently found a Chrome extension that makes Chrome able to properly open and display markdown files: Markdown preview.

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.

Solution 3:

You can actually use pandoc to compile to document format of your choice and view it using external default command. For example i like to preview it as pdf and i use following setup on Ubuntu.

" pandoc , markdown
command! -nargs=* RunSilent
      \ | execute ':silent !'.'<args>'
      \ | execute ':redraw!'
nmap <Leader>pc :RunSilent pandoc -o /tmp/vim-pandoc-out.pdf %<CR>
nmap <Leader>pp :RunSilent gnome-open /tmp/vim-pandoc-out.pdf<CR>

I compile a document using ,pc and preview using ,pp. Since in ubuntu evince is default viewer and automatically loads changed files. You end up doing only ,pc for your changes to reflect.

PS: I have Leader mapped to ,

Solution 4:

I use Marked.app to preview Markdown files. And have mapped <leader>p to do a preview:

function! s:setupMarkup()
  nnoremap <leader>p :silent !open -a Marked.app '%:p'<cr>
endfunction

au BufRead,BufNewFile *.{md,markdown,mdown,mkd,mkdn} call s:setupMarkup()

If you don't want to drop $4 on Marked.app then you can try Hammer.vim. Change the line to:

map <buffer> <leader>p :Hammer<CR>