When I write html in MacVim I keep the same file open in a web browser so that I can examine the html output. One of the things I dislike about this method is that I constantly have to leave vim, go to the browser, and reload the html to see the updates. Is there a more elegant solution with vim that will dynamically update html ouput as it is typed in vim? I seem to recall that Textmate could do this? Thanks.
UPDATE:
I found the video I was trying to remember. You can find it here:
Add this to your .vimrc:
This will create a map, a command and a function. I could have joined them, but
this way it it’s more clear and I can reuse the function in other places.
The function calls a little AppleScript to set the URL of frontmost tab again,
thus refreshing it. This will work under Safari and WebKit, but I can’t
guarantee that it works with other browsers. If not, google “refresh {browser}
applescript” and use a different script.
The map just calls the command, which calls the function. So you can write your
file and use it to refresh the browser without leaving Vim. Equally, use
:Refreshto do the same.Note that you may want to change some things:
\r, use whatever you feel comfortable with.functions
of WebKit itself. Use Chrome, Firefox, or any other name (with the respective
changes)
A quick note: the extra
-eoptions passed to the program are just for the sakeof readability. Do it in the fashion you want.
Take a look also in auto-commands (check :h autocmd.txt). This will let you
do it in a more automatized way like:
This will call
:Refreshevery time you write a buffer for .html files. Thereare also events for inserted text and so on.