Writing a file with vim doesn’t fire a file change event on OS X


Question or issue on macOS:

I am using watchdog to monitor .less file change events on OS X. If I change the contents of a .less file with TextMate or Sublime Text the modification event is captured. However, if I edit the content with vim no file modification event is fired (but file creation events for files created with vim are captured). I have seen the same behaviour with FSEvents and kqueue (both of which I have practically zero knowledge of).

I wonder can anybody explain this behaviour?

How to solve this problem?

Solution no. 1:

Vim normally does not create a temporary file and then rename it. This is so that filesystem aspects such as links (both soft and hard) are preserved when writing files. This is discussed briefly in the Writing section of the Vim documentation, with further information in the 'backupcopy' option documentation.

Your file change events might be limited to changing directory entries.

Solution no. 2:

On Watchdog’s readme there is a section specifically targeting the problem you describe: About using watchdog with editors like Vim. It is suggested to use set noswapfile in your ~/.vimrc.

Hope this helps!