xmlvim

Vim foldmethod=indent when indent is two spaces


I have XML which looks like this:

<object>
  <object>
    a
  </object>
  <object>
    b
  </object>
</object>

and to edit it more easily, I would like to use folding, but when I try set foldmethod=indent it does nothing. Possible it have something to do with that my xml is indented with two spaces, not four, but I'm not sure about that.

How to turn on indenting for such file properly?


Solution

  • You should bear in mind that the foldlevel is computed from the indentation of the line, divided by the shiftwidth & rounded down. If you haven't set sw correctly, VIM might never create a fold where you expect it to.

    Setting :set sw=2 should give you the expected results.