Vim – Automatically Make Scripts Executable

Add this to your vimrc:

au BufWritePost * if getline(1) =~ “^#!” | if getline(1) =~ “/bin/” | silent !chmod a+x | endif | endif

Now, whenever you save a file which has its first line starting with #! (e.g. #! /bin/python), it will become executable.

Enjoy :-)

Leave a Reply