Hacker News new | past | comments | ask | show | jobs | submit login
Refresh Firefox on Vim save (wikia.com)
46 points by csmeder on June 27, 2010 | hide | past | favorite | 24 comments



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/


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


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


And if you are on a mac, you can do something like this instead of the xdotool line:

silent !osascript ~/.vim/refresh.scpt

Where refresh.scpt looks like this:

  tell application "Safari"
	activate
	set rURL to URL of current tab of front window
	set URL of current tab of front window to rURL
  end tell
Or like this (this form preserves the location on the page)

  tell application "Safari"
	activate
  end tell

  tell application "System Events"
	tell process "Safari"
		keystroke "r" using {command down}
	end tell
  end tell


Won't that refresh all instances of Chrome?


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.


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!


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


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.


Given the first letter of any technology and an English word, it's likely that there is a module / plugin / script / program with a name that combines the two.

For example, there are at least two "eproject" extensions for Emacs.


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).


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!"


It's just more keypresses mainly, but also you are unnecessarily changing focus to the browser. If you have your Vim session set to "Always on Top" or to one side, you never have to leave the editor to see your changes.

(On a side note, I wish I could use "Always on Top" in Windows. Anyone know if this is possible?)


I can only guess the author is still using twm. I know a professor and a sysadmin that do at my alma mater, or at least they did circa 2008.


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


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.


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.


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


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


Because you have to remember what you did to copy it over. But FireDiff extension may help in this case.


Correct, I think for the most part it would be a bad way to test code. The only reason I included *.erb is for when I am editing the content/design of a page. Like changing a h2 to a h3 or something like that.


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.


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


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.




Consider applying for YC's Summer 2025 batch! Applications are open till May 13

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: