Reputation: 41817
Vim 7.0.237 is driving me nuts with indentexpr=HtmlIndentGet(v:lnum)
. When I edit JavaScript in a <script>
tag indented to match the surrounding html and press enter, it moves the previous line to column 0. When I autoindent the whole file the script moves back to the right.
Where is vim's non-annoying JavaScript-in-HTML/XHTML indent?
Upvotes: 6
Views: 8145
Reputation: 6842
I have plugins for indenting HTML and JavaScript files. To indent JavaScript inside HTML, I temporarily change the file type, select and indent the lines, and then change the file type back.
:filetype javascript
(select lines)
=
:filetype html
It's a little tedious, but it always produces the results I expect.
Upvotes: 0
Reputation: 55900
I recommend installing vim-javascript.
It is an up-to-date plugin that properly indents javascript, including more recent developments like the syntax used in closures such as with jQuery.
Upvotes: 1
Reputation: 11232
Here is similar question with accepted answer with links to two vim plugins:
One of them solved my problems with JavaScript scripts indention problems.
Upvotes: 5
Reputation: 45381
Personally I toggle between :set ai
and :set noai
, but might be too tedious for you.
Upvotes: 0