I am using the awesome
It provides an
:Autoformat command, which you can bind to the
BufWrite event like so
au BufWrite * :Autoformat
EDIT For if you're only interested in indenting your file (not full-fledged formatting): vim-autoformat falls back to auto indenting your file if js-beautify is not installed.