Reputation: 2836
Just getting started with Vim and am writing a basic HTML file. In SublimeText you could just right click and open in browser, but i'm having trouble finding how to do the same with Vim. I have Ubuntu and I want to preview the code in Chrome.
Thanks!
Upvotes: 1
Views: 481
Reputation: 31040
You can use :!
to execute external commands within vim (see :help :!
). The %
sign in an :ex
command expands to the current file name (see :help :_%
). That being said, you can use the following to first save the file and then open it in the browser of your choice
:w|!google-chrome %
If you'd rather use firefox or chromium, use firefox
or chromium
, respectively, in place of google-chrome
. If you're on mac or linux you could also use the open
or xdg-open
commands, respectively, to open the file in its default application. Don't want to type that out every time? Make your own command or mapping in your .vimrc.
command! ViewInBrowser :w|!google-chrome %
nnoremap <leader>b :ViewInBrowser<cr>
Upvotes: 3