Open current file in Chrome with Vim

Hold on Cowboy

This blog post is pretty old. Be careful with the information you find in here. It's likely dead, dying, or wildly inaccurate.

Most of the time when I’m working on a Markdown document like a README, I want to preview it in Chrome as markdown. Perhaps I’m working on an HTML document and want to preview it in Chrome. It would be a real pain to go to Chrome and then look for the file I’m working on. Luckily Vim makes this really easy.

The Setup 

Add this to your .vimrc

" Open up current file in chrome
nmap <silent> <leader>ch :exec 'silent !open -a "Google Chrome" % &'

(Optional) Add a Markdown viewer to Chrome. I use Markdown Preview Plus.

Now in Vim you just need to enter these commands in Normal mode (hint: my <leader> is ,)

,ch[Enter]

That’s all there is to this. It allows you to simply open the current file in Chrome.

References 

Did this help you out? It took me a few days to piece together all this information together, I hope this saves you some time (who knows, maybe the future me will be thankful I wrote this down). Let me know your thoughts. shanestillwell@gmail.com