asb: head /dev/brain > /dev/www

My home, musings, and wanderings on the world wide web.

Editing markdown in Vim and previewing in Firefox.

Lately, I have taken to maintaining most of my text in Markdown (desperately trying to avoid Emacs’ org-mode) and previewing it while editing in Vim is something that is a nice to have. So I searched a little bit and found this nice little snippet by Ellen Gummesson that I then adapted per my preferences as such:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
" Preview markdown in Firefox

function! PreviewMarkdown()
  let outFile = expand('%:r') . '.html'
  silent execute '!cd %:p:h'
  silent execute '!python -m markdown % >' . outFile
  " The screen will need to be redrawn. Dunno why! :\
  silent execute 'redraw!'
endfunction

augroup markdown
    au!
    au BufNewFile,BufRead *.md,*.markdown setlocal filetype=ghmarkdown
    au BufNewFile,BufRead *.md,*.markdown setlocal textwidth=0
    autocmd FileType ghmarkdown map <LocalLeader>p
          \ :call PreviewMarkdown()<CR>
augroup END