Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get vim to modify the file instead of moving the new version on it?

Tags:

vim

I want my app to update automatically when I save my files. So I use inotify (ubuntu) to create watchers that detect the events.

The issue is vim overwrites the file instead of updating it. So my watcher is lost after the first update.

I wonder, is there a way to setup vim so it doesn't use swap files and updates directly the file ?

(I tried :set noswapfile and the -n option, that removes the swap file without changing the behaviour)

like image 241
Simon Avatar asked May 08 '12 22:05

Simon


2 Answers

You can do this:

:set backupcopy=yes
like image 163
kev Avatar answered Oct 19 '22 10:10

kev


With Vim, you can control this via the 'backupcopy' setting; however, I once took an alternative route and monitored the directories, not the files themselves:

inotifywait --quiet --monitor --event modify --format '%w%f' "$dir"

This required some more processing in my script (checking whether the modified file matches my list), but also enabled me to capture newly created files, too.

like image 23
Ingo Karkat Avatar answered Oct 19 '22 10:10

Ingo Karkat