Greetings from scenic,

prettyboytellem.com

Category: Rice
Tags: Vim Test-file

Stop Vim from Overwriting Extended Attributes

There's a pretty undocumented issue with the Vim editor which affects files containing extended attributes (xattrs).

Vim may overwrite files instead of updating them. In addition to creating some trouble with inotify watcher and events, this process also clobbers the extended attributes of a file. This can be problematic if you happen to store information within the files's xattrs. For example, I store an MD5 hash in some of my articles; when I edit an article, the actual checksum will differ from the one in xattr, and my Perl script will know to update the article on this website.

This tendency of Vim is controlled by the backupcopy variable. By default, backupcopy=yes for Unix and backupcopy=auto otherwise. Some distributions will unset backupcopy, so it may be necessary to put the following in your .vimrc file:

set backupcopy=yes

Now extended attributes should be preserved across writes. To test this, do the following in a shell:

touch test-file setfattr -n user.attr1 -v v1 test-file vim test-file # Add some text and :wq getfattr test-file

Although some claim that this slows down the :w command, I've not seen a measurable difference in performance since using this setting.


Related / Browse