简体   繁体   中英

In Vim, how do you open an html file in a browser without creating a new tab?

Currently, when editing HTML files, I preview them using the following mapping: nnoremap cc :w <CR> :!open -a /Applications/Google\\ Chrome.app %<CR><CR> . However, this always opens up a new tab. Is there any way of mapping such that a new tab is only opened if the currently edited HTML file has not been opened in your browser yet, and refreshes the page in which your HTML file has been loaded otherwise? Thanks.

There is AFAIK no way to tell Chrome to refresh the current tab from the outside.

But, you can try one of the many extensions that provide automatic reloading:

  • LiveReload

    That one never worked for me and requires too much fiddling.

  • Tincr

    That one used to be fantastic but suddenly stopped working a few Chrome versions ago. Worth following, though.

  • LivePage

    That one has a simpler design than the two above. It has been working perfectly for me as a replacement for Tincr

You can also deal with the situation from the other end with Prepros , a great HTML/CSS/JS preprocessor that, among many other useful features, does live preview.

Due to various reasons I'm unable to use Prepros everywhere so my current workflow involves Koala for the pre-processing — which runs everywhere I need it to run —, LivePage for live refresh and… no mapping in Vim.

--- edit ---

Your question is about Chrome, but I thought it would be useful to also mention Auto Reload , a Firefox extension similar to the ones listed above that works beautifully.

--- end edit ---

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM