Usually, I think there are better ways to write code today but often vim is simply useful because you are on an ssh connection or in a virtual environment or whatever.

Anyway, to get the IMHO quite cool auto-indent feature when pressing
“Tab” like emacs does, simply put this in your .vimrc:


set cindent
set smartindent
set autoindent
set expandtab
set tabstop=2
set shiftwidth=2
set cinkeys=0{,0},:,0#,!,!^F

Of course you can read more about the vim indenting feature in the documentation. Of course, I think most of you will know that already, so this entry is more a reminder for me.

[EDIT] uws remindend me, that the first three lines were missing. Seems the default on my system already included them. Thanks!

One Response to “Getting cool auto-indent in vim”

  1. danielk Says:

    I think it’s better to leave tabstop at its default value and set softtabstop=2 instead.


Comments are closed.