From BStegmaier

Jump to: navigation, search
  • Adding this to your .vimrc automatically sets the execution mode-bit when editing files beginning with shebang #! and a path containing bin
" automatically give executable permissions if file begins with #! and contains '/bin/' in the path
" see http://www.debian-administration.org/articles/571
" modified 23.12.2008 Benedikt Stegmaier <dev _at_ bstegmaier _dot_ de>
"
function MakeScriptExecuteable()
    if getline(1) =~ "^#!.*/bin/"
        silent !chmod +x <afile>
    endif
endfunction
    
au BufWritePost * call MakeScriptExecuteable()