10

For example, if I have some JavaScript code like this:

var widget = library()
  .chainCall1()
  .chainCall2()
  .chainCall3();

If I use the = command to auto indent it, it comes out looking this this:

var widget = library()
.chainCall1()
.chainCall2()
.chainCall3();

Which isn't what I want. I want it to indent the chain calls like it originally was. How can I fix this?

aharris88
  • 1,847
  • 2
  • 17
  • 22
  • @janos Mine not only un-indents .chainCall2(), it indents the var line to match .chainCall1() =o_0= – Izkata Feb 05 '15 at 00:26

1 Answers1

3

I had the same problem - for the most part the JavaScript formatting done by vim is not bad, but in examples like the one you give it fails miserably.

I've been using the vim-jsbeautify plugin to fix things where the vim indentation fails, and also to clean up ugly code other people have written. It works really well, you can run it on the whole file or just a region, and it's customisable using an EditorConfig file.

craigp
  • 2,481
  • 20
  • 13