I’ve been using grunt-contrib-watch to automate various processes that run when a file is changed, lately. It’s a pretty slick tool that has helped me create a pretty slick setup. But I was consistently running in to a problem where a single file save from macvim would cause two change events to fire in the watcher. This wasn’t a huge issue, but having everything process twice got to be annoying.
After a bit of searching, I found that Jeff Schwartz had run in to / solved this problem in macvim already.
According to the research that Jeff did:
On OSX, Vim defaults this to “set backupcopy=auto”, which results in Vim making 2 changes to the original file when saving it, resulting in the 2 change events which are handled by watch.
The solution is simple: set
backupcopy=yes in your ~/.vimrc file to prevent this from happening. Once it put that in place, everything was fine and I only saw the expected 1 file change event when saving a file.