How to execute the contents of a buffer?
Use:
:%y" (alternatively: ggyG)
:@"
It will copy whole buffer into default register and then run it.
See :help :y
and :help :@
(and also :help range
maybe).
An autocmd to source the file whenever you save might help:
autocmd BufWritePost <buffer> source %