How to Autoindent Ruby source code in Vim

user815693 picture user815693 · Dec 16, 2011 · Viewed 13k times · Source

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

Answer

m0tive picture m0tive · Dec 16, 2011

Try using smartindent instead of cindent (which follows C-like indent behaviour), and turn on the filetype specific indent.

You'll also probably need to turn off vi compatibility.

Try adding this to you .vimrc:

" Turn off vi compatibility
set nocompatible

set smartindent
set autoindent

" load indent file for the current filetype
filetype indent on