$ ls sess.vim -lh              -rw-r--r-- 1 root root 11K Feb 26 18:52 sess.vimI want this file to be readable for everyone and writable by no one (except by root). Thus I set its permissions to 644 and ownership to root:root.  $ echo text >> sess.vim      zsh: permission denied: sess.vimSeems fine. After some changes in vim I do :w! (force write) and the file is saved successfully. Now:$ ls sess.vim -lh-rw-r--r-- 1 MY_USERNAME users 11K Feb 26 19:06 sess.vimWt.. Why? How?
Vim writes to file without having permissions
files;permissions;vim
Using :w! in vim is similar to the following:echo 'test' > sess.vim.tempmv sess.vim.temp sess.vimThe mv commands only cares about the directory permissions, the permissions of the file are not relevant. This is because you are modifying the directory, not writing to the file. To accomplish your goal, you will also need to adjust the permissions of the directory the file resides in.