Tuesday, May 7, 2024
 Popular · Latest · Hot · Upcoming
151
rated 0 times [  155] [ 4]  / answers: 1 / hits: 27931  / 16 Years ago, fri, march 6, 2009, 12:00:00

I can't seem to get inline Javascript indenting properly in Vim. Consider the following:



  $(document).ready(function() {

// Closing brace correctly indented
$(input).focus(function() {
$(this).closest(li).addClass(cur-focus);
}); // <-- I had to manually unindent this

// Closing brace incorrectly indented
$(input).blur(function() {
$(this).closest(li).removeClass(cur-focus);
}); // <-- This is what it does by default. Argh!

});


Vim seems to insist on automatically indenting the closing brace shown in the second case there. It does the same if I re-indent the whole file. How do I get it to automatically indent using the more standard JS indenting style seen in the first case?


More From » vim

 Answers
33

Use JavaScript Indent: Javascript indenter (HTML indent is included) by Preston Koprivica. Thanks for the heads-up from oligofren - give him an up-vote.


[#99882] Saturday, February 28, 2009, 16 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
raveno

Total Points: 453
Total Questions: 92
Total Answers: 92

Location: France
Member since Thu, Oct 27, 2022
2 Years ago
raveno questions
;