Vim runs multiple saves
I am facing a problem using nodemon
together withvim
nodemon is a deamon that monitors files and runs a script every time the file changes.
The weird thing is, when I run nodemon and save a file with vim, nodemon detects two file files.
You can replicate this issue with the following snippet:
npm install nodemon -g
echo "console.log('hello world');" > server.js
nodemon server.js -V
vim server.js
Then try to save the file (with :w
)
It seems that every time I save a file from vim, the clock starts twice. However, if you open server.js
with pico
, the file changes only once.
I don't think nodemon is the problem, so I ask what could create this particular behavior?
I also tried to disable all vim plubins vim -u NONE server.js
but that didn't help.
They're also a related issue on github: https://github.com/remy/nodemon/issues/349 , however it doesn't seem easy to figure out what's going on.
source to share
It has to do with Vim's file write handling. See :help 'backupcopy'
for explanation. Editors such as Vim replace the original file with a temporary backup to avoid losing the contents of the file entirely. This is also a problem when viewing the file for changes through inotifywait
( see here ). The workaround for this is
:set backupcopy=yes
You will still see events for the backup file, but at least for the other file. To drop the backup security entirely, you can add
:set nobackup
source to share