EDIT: I initially answered with the correct, but ultimately irrelevant information on how UNIX permissions work: this is not what Vim did.
Indeed, you are right: when you release :w! , and you work on UNIX, Vim will add write permission if it needs to:
if (forceit && perm >= 0 && !(perm & 0200) && st_old.st_uid == getuid() && vim_strchr(p_cpo, CPO_FWRITE) == NULL) { perm |= 0200; (void)mch_setperm(fname, perm); made_writable = TRUE; }
and then reset back:
if (made_writable) perm &= ~0200; /* reset 'w' bit for security reasons */
This is also reflected in the help:
Note. . This can change the permission and ownership of files and broken (symbolic) links. Add the 'W' flag to "cpoptions" to avoid this.
source share