When editing an existing file with VIM: will it replace or change that file?

6

1

I've read that most editors will replace the file when you actually want to save changes to that file How to execute a command whenever a file changes?. So how does VIM behave?

math

Posted 2012-05-04T11:21:36.290

Reputation: 2 376

Answers

5

it might depend on various settings related to 'backup', everything that has to keep a copy of the file as it was before the write happened. one of settings that controls that is: 'backupcopy':

When writing a file and a backup is made, this option tells how it's done. This is a comma separated list of words.

The main values are:

"yes"    make a copy of the file and overwrite the original one
"no"     rename the file and write a new one
"auto"   one of the previous, what works best

so, depending on your vimrc (backup set and backupcopy to no), vim might rename a file. when

akira

Posted 2012-05-04T11:21:36.290

Reputation: 52 754

Yeah this also complies with my observation that inotifywait printed the same inode number that has changed.. – math – 2012-05-04T11:46:18.803

1comment on @math's comment: i changed the answer quite a bit after his comment. the former version stated that the test i did wrote into the same inode / file. but since my vimrc runs without backup ... not a valid test :) – akira – 2012-05-04T14:31:19.720