Is there a plugin / program / key binding that will let me preview html files that I am editing in vim in a browser?

Background: I have abandoned traditional full-feature editors and IDE's (of which I was once a big fan!). As time has gone by I've realized that most of the skills and knowledge isn't transferable. So now I stick with vim, tmux and the like. btw I need high visibility so I need panes not tabs.

I'm not looking for the best tool. Any one would do. Maybe it can be done with a key binding?


Love the idea!

Here's a simple keybinding you can insert into your .vimrc:

nnoremap <C-p> :!google-chrome %<CR>

Replace google-chrome with your favorite browser. This allows you to preview the file you're working on if you press Ctrl + P in normal mode.

The only caveat is that this will open a new browser tab each time you ask it to preview the file.

[From OP: I ended up using:

nnoremap <C-g> :!google-chrome %<CR> " browser preview with ctrl-p
nnoremap <C-f> :!firefox %<CR> " browser preview with ctrl-o
nnoremap <C-c> :!chromium-browser %<CR> " browser preview with ctrl-c


ctrl-f and ctrl-c had previous uses (folding and moving to the bottom) but I wasn't using them so this is ok. Added these at the bottom of the .vimrc file.

  • +1 what about different browsers - different key for each? Jun 7 '14 at 13:13
  • @MichaelDurrant You can extend this ad infinitum, of course. Make it <C-g> for Chrom(e|ium), <C-f> for Firefox, and so on...
    – Joseph R.
    Jun 7 '14 at 13:15
  • ha, yup, that's exactly what I tried, f and g. Working well! Jun 7 '14 at 13:21
  • note chromium-browser name for chromium Jun 7 '14 at 13:30
  • I think my " comments are possibly invalid btw - but that has the side-effect of eliminating the prompt which gets tiresome. Call it a beneficial bug :) Jun 7 '14 at 13:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.