11

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?

John Keyes
  • 5,479
  • 1
  • 29
  • 48
  • 1
    Does vim write to a temp file, then rename the temp file to the name of the file you're working on? – Matt K Sep 29 '11 at 01:38
  • That may be something to do with it. The only spanner in the works is that when I `mv` a file it triggers a move/rename event. I wonder why vim's save doesn't do that? Nothing events are fired when I write from vim. I can see .swp files beings created when I begin editing though. – John Keyes Sep 29 '11 at 01:46

2 Answers2

4

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.

Stefano Masini
  • 452
  • 3
  • 11
3

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.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
  • Thanks for the information Greg. As I mention above though, I can see the file events when I edit with TextMate or Sublime Text. – John Keyes Sep 29 '11 at 01:56
  • It sounds like those editors write files in a different way than Vim does (perhaps similar to setting the `backupcopy` option to `no` in Vim). – Greg Hewgill Sep 29 '11 at 01:57
  • 3
    I set the following: set nobackup, set noswapfile, set nowritebackup; and the modified events were fired. – John Keyes Sep 29 '11 at 02:04
  • 2
    FYI, this is documented in the README on github that you linked to. – dicato Oct 05 '11 at 20:19
  • 1
    For posterity finding this, I believe `set backupcopy=yes` is the key piece: force Vim to write to the original file, not copying it as the backup and writing to a new file. This allows you to keep `set backup` and `set writebackup` if you prefer. `swapfile` is irrelevant here. – ches Jun 16 '16 at 11:22