Apr 10, 2015

I don't know about you, but I love me some Markdown. It's makes it super simple to write blogs as this one and add "rich text" to any application. It's become a awfully popular and most newer editors have been updated to give the user a side-by-side preview when writing Markdown. But I don't want to leave the safety of my Vim. So I searched around and found Marko!

Marko is a super simple app that's only purpose it to preview a Markdown file. In order to make it even more useful when paired with Vim I wrote a small function to open the current file in Marko.

function! s:Marko()
  noautocmd silent execute "!open -a \"Marko\" " . expand("%:p")
  if v:shell_error
    echohl Error
    echon "Problem opening the file."
    echohl Normal
  endif
endfunction

command! -bar -nargs=0 Marko call s:Marko()

Simply put that somewhere in your vimrc and type :Marko.

marko split

Bam! Super simple side-by-side Markdown editing with Vim. While this fuction is useful to open something in Marko, it can easily be used for opening files in other apps too. Or you could even change it a bit to tell Vim what app to open the current file with.

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Open current file with app given
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! s:OpenWith(appname)
  noautocmd silent execute "!open -a \"" . a:appname . "\" " . expand("%:p")
  if v:shell_error
    echohl Error
    echon "Problem opening the file."
    echohl Normal
  endif
endfunction

command! -bar -nargs=1 OpenWith call s:OpenWith(<f-args>)

Edit

Checkout the reddit post for some other alternatives. I tried out /u/i_know_sherman's suggestion with ianks/octodown and it's really simple and free. I also downloaded Marked from /u/gordiep's suggestion and it's now taken the place of Marko.