used to put the backup
file in. (default: same directory as the written file).
Whether the backup is a new file, which is a copy of the original file, or the
original file renamed depends on the 'backupcopy' option. See there for an
explanation of when the copy is made and when the file is renamed.
If the creation of a backup file fails, the write is not done. If you want
to write anyway add a '!' to the command.
*file-watcher*
When you notice issues with programs, that act upon when a buffer is written
(like inotify, entr or fswatch) or when external applications execute Vim to
edit the file (like git) and those programs do not seem to notice that the
original file has been changed, you may want to consider switching the
'backupcopy' option value to "yes". This makes sure, Vim writes to the same
file, that those watcher programs expect, without creating a new file (which
prevents them from detecting that the file has changed). See also |crontab|
*write-permissions*
When writing a new file the permissions are read-write. For unix the mask is
0o666 with additionally umask applied. When writing a file that was read Vim
will preserve the permissions, but clear the s-bit.
*write-readonly*
When the 'cpoptions' option contains 'W', Vim will refuse to overwrite a
readonly file. When 'W' is not present, ":w!" will overwrite a readonly file,
if the system allows it (the directory must be writable).
*write-fail*
If the writing of the new file fails, you have to be careful not to lose
your changes AND the original file. If there is no backup file and writing
the new file failed, you have already lost the original file! DON'T EXIT VIM
UNTIL YOU WRITE OUT THE FILE! If a backup was made, it is put back in place
of the original file (if possible). If you exit Vim, and lose the changes
you made, the original file will mostly still be there. If putting back the
original file fails, there will be an error message telling you that you
lost the original file.
*DOS-format-write*
If the 'fileformat' is "dos", <CR><NL> is used for <EOL>. This is default
for Windows. On other systems the message "[dos]" is shown to
remind you that an unusual <EOL> was used.
*Unix-format-write*
If the 'fileformat' is "unix", <NL> is used for <EOL>. On Windows
the message "[unix]" is shown.
*Mac-format-write*
If the 'fileformat' is "mac", <CR> is used for <EOL>. The
message "[mac]" is shown.
See also |file-formats| and the 'fileformat' and 'fileformats' options.
*ACL*
ACL stands for Access Control List. It is an advanced way to control access
rights for a file. It is used on new MS-Windows and Unix systems, but only
when the filesystem supports it.
Vim attempts to preserve the ACL info when writing a file. The backup file
will get the ACL info of the original file.
The ACL info is also used to check if a file is read-only (when opening the
file).
*xattr* *E1506* *E1508* *E1509*
xattr stands for Extended Attributes. It is an advanced way to save metadata
alongside the file in the filesystem. It depends on the actual filesystem
being used and Vim supports it only on a Linux system.
Vim attempts to preserve the extended attribute info when writing a file.
The backup file will get the extended attribute of the original file.
*read-only-share*
When MS-Windows shares a drive on the network it can be marked as read-only.
This means that even if the file read-only attribute is absent, and the ACL
settings on NT network shared drives allow writing to the file, you can still
not write to the file. Vim on Win32 platforms will detect read-only network
drives and will mark the file as read-only. You will not be able to override
it with |:write|.
*write-device*
When the file name is actually a device name, Vim will not make a backup (that
would be impossible). You need to use "!", since the device already exists.
Example for Unix: >
:w! /dev/lpt0
and MS-Windows: >
:w!