

Refresh Firefox on Vim save - csmeder
http://vim.wikia.com/wiki/Refresh_Firefox_(preserving_scroll)_on_Vim_save,_using_MozRepl

======
willwagner
I have a simple tool for autorefreshing a page on save too, albeit you need to
add a script tag to the html you are editing which adds a comet connection
behind the scenes. Works across browsers so you can have IE, firefox, and
chrome all running in different windows and see them all refresh every time
you save a change.

<http://www.willwagner.com/autorefresh/>

~~~
anurag
Just tried it out - works well for editing code over SSH. Great work, thanks.

------
vault_
If you're on Linux and use a different browser you can do the same using
xdotool.

    
    
        autocmd BufWriteCmd *.html,*.css,*.haml :call Refresh_browser()
        function()! Refresh_browser()
            if &modified
                write
                silent !xdotool search --class google-chrome key ctrl+r
            endif
        endfunction

~~~
jamesbritt
Won't that refresh _all_ instances of Chrome?

~~~
vault_
You'd think so, but when I was doing some quick testing with just one window
and multiple tabs it only refreshed the current tab. Doing some more tests now
with multiple windows, it seems to only refresh the active tab of the back-
most window in the stack.

I think that's rather counter-intuitive, but I doubt it'd be much of an issue
in practice.

------
mgrouchy
Another awesome tool to do this is <http://xrefresh.binaryage.com/>

No vim hack required. However, this is my first hearing of MozRepl(out of the
loop I know). I now have a bunch of ideas for interesting things that I can do
with it, thanks!

~~~
Dobbs
I was very confused when I saw this link. There is another program called
xrefresh that forces X11 to redraw all applications.

~~~
woid
Hey Antonin here. I'm the author of xrefresh from binaryage. Yes, my bad. I
started this project in the times when I was pure windows user and has no
awareness of X11 utility. xrefresh stands for "eXternal refresh" which sounded
kinda cool.

------
watchdogtimer
If the goal is not take your hands off the keyboard, why not save, then Alt-
TAB once to get to Firefox, then Cntrl-R to refresh? This works with any
editor (including my favorite, nvi).

~~~
bradleyland
I used to use the same keyboard sequence, but since I started using an editor
with the ability to "refresh in running browsers", I can attest to value of
the reduction in inane repetition. It's nothing life changing, but when you
experience it it, the feeling is kind of like the one you have when you first
encounter lights that come on automatically when you enter a room: "Hey,
cool!"

------
csmeder
Maybe this is well known, in that case disregard this submission. However, if
your like me and never thought to do this and you do a lot of Sass or css
editing in vim then this article is a huge help.

Note: make sure to include _.sass,_.erb in your .vimrc if your using Sass and
Rails. For example

    
    
      autocmd BufWriteCmd *.html,*.css,*.gtpl,*.sass,*.erb :call Refresh_firefox()
    
    

2nd note: Make sure to start MozRepl:

Go to Firefox Tools menu and select MozRepl → Start

------
datapimp
I've found that saving code, and refreshing the browser, then going back to
code, then going back to the browser, is a terribly inefficient practice and
horrible for flow. If you're finding yourself having to do this so often as to
require a vim hack, you're doing something wrong.

Something like autotest for ruby projects, and cucumber / selenium etc should
be making sure your code does what it is supposed to.

~~~
samdk
Horrible for code, maybe. For doing design with CSS(/Sass/etc) though it's
essential.

I do :w, Alt-Tab, Ctrl-R _constantly_ when I'm doing design. I'm constantly
testing little changes. This looks like it could be quite a useful little
hack.

~~~
mitjak
Why not just do it all in firebug and then copy the final result over?

~~~
csmeder
Thats like asking why not dig ditches with a spoon? Sure its possible but any
one who has tried a Shovel or a back hoe is going to hate it.

see this slide: <http://www.slideshare.net/c9s/perlhacksonvim>

------
mbenjaminsmith
The poor man's version I use on Chrome is to add one of the plugins that will
autorefresh every n seconds. It's far from ideal, but if I'm working on css it
saves me a lot of time.

Another hack I've put together is to use applescript and a keyboard shortcut.
Set it up as a universal shortcut and give focus to your code editor at the
end of the script.

------
awt
Another alternative is to use Playground:
<http://owyheesoftware.com/playground>. It works with any text editor.

------
tzs
Why not generalize? Have a background process that watches the file, and
whenever the modification time changes, refresh the browser. Then it works
with any editor.

