Search code examples
rubyvimauto-indent

How to Autoindent Ruby source code in Vim


suppose I have set cindent in .vimrc
def func() followed by Enter, and then type end, it is indented(not aligned to the def)

How to reindent the end keyword(align it to the def).

Even using endwise.vim plugin doesn't fix the problem
https://github.com/tpope/vim-endwise.git
It adds automatically the end keyword but again indented


Solution

  • vimfiles includes ruby code smart indention and a lot of other useful things

    ruby code is automatically formatted like

    class Foo
      def bar
        if xxx
          blah
        else
          blahblah
        end
        barfoo
        barfoo
      end
    end