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!
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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.