if exists('*function') " New Bourne shell script command! -nargs=1 -complete=file New :call NewScript("", "#! /bin/sh\n# (Bourne shell script) -- \n") command! -nargs=1 -complete=file NewSh :call NewScript("", "#! /bin/sh\n# (Bourne shell script) -- \n") command! -nargs=1 -complete=file NewBash :call NewScript("", "#! /bin/bash\n# (BASH script) -- \n") command! -nargs=1 -complete=file NewPython :call NewScript("", "#! /usr/bin/python3\n# (Python script) -- \n") command! -nargs=1 -complete=file NewAwk :call NewScript("", "#!/usr/bin/awk -f\n# (AWK script) -- \n") command! -nargs=1 -complete=file NewSed :call NewScript("", "#! /bin/sed -f\n# (Sed script) -- \n") command! -nargs=1 -complete=file NewPerl :call NewScript("", "#!/usr/bin/perl --\n# (PERL script) -- \n") command! -nargs=1 -complete=file NewPHP :call NewScript("", "#!/usr/bin/php\n", 3) "# command! -nargs=1 -complete=file New :call NewScript("", "\n") function! NewScript(args, template, ...) if a:0 > 0 let s:linenum = a:1 else let s:linenum = 2 endif exe "edit " . a:args if wordcount()['bytes'] > 0 echoerr "File/buffer exists" else setlocal filetype=sh put! =a:template exe "normal! " . s:linenum . "Gla" . expand('%:t') . "\" setlocal autoread write silent call system("chmod +x " . shellescape(a:args)) write set autoread< modified endif normal $ endfunction endif