Executable bit on files created by vim

executablevim

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.

Best Answer

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

Related Question