I'm aiming to make scripts I write in a certain directory (or of a certain extension) automatically executable on creation. I can do this whenever a file is written to, using the following
autocmd BufWritePost *.py silent execute "! chmod +x %"
What I don't like is that this runs every time the file is written. If I had decided to reset the permissions of a particular script, I wouldn't want it to be set again, for example. And if the command is expensive, or is not idempotent, it would be undesirable to run it again and again. While this particular example uses
chmod, please consider a more general case.
There is an event for when a buffer is created for a new file (
BufNewFile), but is there some way to do this when such a buffer is written the first time?