I need help getting VIM to correctly indent javascript inside script tags.
This is what I want it to look like:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-257015-24']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
This is what it looks like when I let VIM indent, which is quite nice, but not optimal:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-257015-24']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
My VIM files are roughly these ones: http://github.com/lunks/vimfiles
I have tried appending script to the tags I want to indent on my vimrc:
let g:html_indent_inctags = "body,head,tbody,ul,li,p,script"
But then, although it successfully indents the content following the script tag, it doesn’t indent its contents as javascript anymore, rather it’s just text.
How can I make VIM indent Javascript inside script tags the way I intend to?
This one did it: https://github.com/vim-scripts/indenthtml.vim
Make sure to add to your vimrc: