Execute current file in Vim
Here’s a helpful function you can drop in to your .vimrc that binds F5 to execute the current file if it has a shebang.
function! RunShebang()
if (match(getline(1), '^\#!') == 0)
:!./%
else
echo "No shebang in this file."
endif
endfunction
map <F5> :call RunShebang()<CR>
You’ll need to make sure the file is executable. A similar tip was posted the other day on the Daily Vim blog.