Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
+1 what about different browsers - different key for each? –  Michael Durrant Jun 7 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 at 13:15
    
ha, yup, that's exactly what I tried, f and g. Working well! –  Michael Durrant Jun 7 at 13:21
    
note chromium-browser name for chromium –  Michael Durrant Jun 7 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 :) –  Michael Durrant Jun 7 at 13:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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