1

When I save a file in vim, it does following operations:

$ inotifywait -r -m -c src/
src/,CREATE,4913
src/,OPEN,4913
src/,ATTRIB,4913
src/,"CLOSE_WRITE,CLOSE",4913
src/,DELETE,4913
src/,MOVED_FROM,App.tsx
src/,MOVED_TO,App.tsx~
src/,MODIFY,.App.tsx.swp
<0.5 second pause, probably caused by the hard drive's seek time>
src/,CREATE,App.tsx
src/,OPEN,App.tsx
src/,MODIFY,App.tsx
src/,MODIFY,App.tsx
src/,MODIFY,App.tsx
src/,ATTRIB,App.tsx
src/,"CLOSE_WRITE,CLOSE",App.tsx
src/,ATTRIB,App.tsx
src/,MODIFY,.App.tsx.swp
src/,DELETE,App.tsx~

During the pause in the middle, file-watching compilers often try to compile while the file doesn't exist! Is there a way to make vim copy the file instead of moving it? Or is there another way to solve the problem?

(note, it looks like vim does copy backups automatically in some directories but not others)

3
  • 2
    See :help 'backupcopy', together with related options ('backup', 'writebackup'), I'm not sure which exact combination of options you need but check them to see if you find the one that works right for your use case...
    – filbranden
    Jul 30 at 3:01
  • 1
    Thanks! set backupcopy=yes maked it do it in all directories, solving the issue. Jul 31 at 4:00
  • Welcome to Vi and Vim!
    – D. Ben Knoble
    Aug 1 at 16:13
1

This works: :set backupcopy=yes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.