Auto indent javascript code in Vim on save
I am using an awesome vim-go
Go coding plugin with vim. ( https://github.com/fatih/vim-go )
A feature I love is automatic indent on save. I would like to get the same behavior for javascript files. Do you know any way to easily reproduce this in js?
Many thanks
source to share
There is a generic auto-formatting module for vim called vim-autoformat that bundles js-beautifier (engine behind http://jsbeautifier.org/ online app ), etc.
It provides a command :Autoformat
that you can bind to an event BufWrite
, for example:
au BufWrite * :Autoformat
EDIT If you are interested in indenting your file (not full formatting): vim-autoformat falls back to auto indenting your file if js-beautify is not installed.
source to share