There is no good way to format javascript source with vim.
If you type ggvG= then it will get confused.
Vim does not understand enough of javascript.
So this is what you do.
First fire up your package manager and install node.js.
It may be called just node, or server side javascript.
Then install this.
# npm install -g js-beautify
This is a node.js package for formatting javascript.
Then plonk this line in ~/.vimrc
nnoremap <leader>ff :%!js-beautify -j -q -B -f -<CR>
Now fire up vim and type
\ff
and your code will get nicely formatted.
Cool.
-Girish
--
Gayatri Hitech
http://gayatri-hitech.com