Vim can detect syntax based on filename or on shbang lines, but if you're creating for example a new perl script and you don't want to use the .pl extension, vim will not automatically detect that after you type #!/usr/bin/perl. Instead, you manyally have to type :filetype detect. There must be a better way!
But of course there is a better way, there's vimscript!
function! RedetectFiletype() if getpos(".") == 2 && getline(1) =~ '^#!' filetype detect endif endfunction inoremap <CR> <CR>:call RedetectFiletype()<CR>i<BS><CR>
So if you write a new shbang and hit enter, vim will take the hint and try to guess what kind of syntax you will be using.