Chris Sutter writes:
I have a script and mapping in my ~/.vimrc:
if (match( getline(1) , '^\#!') == 0)
map <F5> :!./%<CR>
map <F5> :call CheckForShebang()
This way, if i'm editing a script with a shebang at the top and i hit <F5>, it maps <F5> to run the script (if not, <F5> is unmapped, so that it doesn't keep checking if I hit it again). I always found myself mapping <F5> by hand to run the current script while i was editting/debugging and I'd frequently lose track of whether I had mapped it or not. You could, of course, replace <F5> with your favorite run/compile/debug/etc key, it just happens to be my standard (from my QBasic days hehe).
Thanks for the tip Chris!