13

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

hakre
  • 193,403
  • 52
  • 435
  • 836
user815693
  • 516
  • 1
  • 6
  • 12

4 Answers4

24

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
m0tive
  • 2,796
  • 1
  • 22
  • 36
  • I get indentation but it's wrong based on filetype? For ruby files I get huge tab indentation, while I'm supposed to get just 2 spaces ? – Redoman Oct 06 '15 at 19:19
  • 1
    And to disable `set nosmartindent`, `set noautoindent`, `filetype indent off` – Dorian Mar 04 '17 at 01:01
1

In my case this is what fixed my indentation issues (e.g. jumps in random places):

set smartindent
set noautoindent
filetype indent off
Dorian
  • 22,759
  • 8
  • 120
  • 116
1

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
zed_0xff
  • 32,417
  • 7
  • 53
  • 72
0

This worked for me.

" Ruby indentation from http://ubuntuforums.org/showthread.php?t=290462
if has ("autocmd")
    filetype indent on
endif
loeschg
  • 29,961
  • 26
  • 97
  • 150