I want to a page to auto-reload every 60 seconds. Luckily, I could just use one-liner in ~/.vimperatorrc:

autocmd PageLoad tw\\.finance\\.yahoo.com\\/pf\\/mypf js (function(){var t=getBrowser().tabs[<tab>-1];window.setTimeout(function(){getBrowser().reloadTab(t)},60000)})()

By using automatic command1 with PageLoad event, I am able to set up a timeout to reload when the page just loaded.

Break down the code:

(function(){
  var t=getBrowser().tabs[<tab>-1];
  window.setTimeout(
    function(){
      getBrowser().reloadTab(t)
      }
    ,60000)}
)()

Vimperator will replace Tab with the tab number (1-indexed) of the tab which page load event occurred, the code stores in t variable with Tab object instead of the tab number. The number may change. When times out, reload with that t. Once page loads again, PageLoad occurs again as well. Another timeout would be set.

I found a plugin2, but I didn’t try it because I don’t want to have many codes. You may want to do some research if you prefer using plugin.

My code has two caveats. First one, you should never manual reload, or you would have multiple reloads, because one more window.setTimeout would be set every time you refresh manually. If you do, open a new tab and close the current one. My code could be improved but I would need to set up a variable to record which tab has been activated for auto-reload and add more controlling codes. I wouldn’t want that, one-liner and keep no manual reload in my mind.

Second one, if you change url of the tab, the new url would be reloaded once since timeout has be set. But it’s only once.

No need to r, r, r, and r, anymore!


[1]http://vimperator.sourceforge.net/help/vimperator/autocommands.xhtml is gone.
[2]http://code.google.com/p/vimperator-labs/issues/detail?id=22 is gone.