Is there any setting for vim create new files with full permissions? that is falling just under the umask restrictions, and only on files created by vim. It shouldn't modify the bits of an already existing file. I've already seen the solution that sets the x bit on for files in /bin/ or starting by #!, but I'd like my vim to obey umask, and umask only.
This has been asked before in various places. In short, vim uses
umask only (like other applications) to turn off permissions, but you can use a script to modify file permissions.
Most applications (such as text editors) treat their output as data, and when opening (creating) a file, use data-style permissions, e.g., 0666, 0644, 0600, etc. Likewise, most programs do not set umask themselves, but merely rely upon existing settings to reduce privileges which they might offer to some users.
Opening an existing file is a different matter. Many editors write the updated file without recreating or renaming it, using the same inode. This happens to preserve the permissions (and ownership) of a file. A few (e.g., vim and vile) have some provision for temporarily changing a file's permissions to write on a "read-only" file. For that, they have to know what the original permissions were, but again
umask is irrelevant to the resulting file permissions.
For further reading
- Vim creating files on superuser shows an example of a script which checks for "#!" at the beginning of the file, and also if the file is written into a directory with "/bin/".
- vim: create file with +x bit repeats that, adding a few other examples.
- addexecmod.vim : add execute permission automatically at saving file is a plugin which simply checks for "#!".