Tab key == 4 spaces and auto-indent after curly braces in VIM

How do I make Vi-Vim never use tabs (converting spaces to tabs, bad!), makes the tab key == 4 spaces, and automatically indent code after curly brace blocks like emacs does?

Also, how do I save these settings so I never have to input them again.

I’ve seen other questions related to this but it always seems to be a little off from what I want.

The Best Anser:

in your .vimrc:

set smartindent
set tabstop=4
set shiftwidth=4
set expandtab

The help files take a bit of time to get used to but the more you read the better vim gets:

:help smartindent

Even better, you can embed these settings in your source for portability:

:help auto-setting

To see your current settings:

:set all

As graywh points out in the comments, smartindent has been replaced by cindent which “Works more cleverly", although still mainly for languages with C-like syntax:

:help C-indenting


在下方填入你的資料或按右方圖示以社群網站登入: Logo

您的留言將使用 帳號。 登出 / 變更 )

Twitter picture

您的留言將使用 Twitter 帳號。 登出 / 變更 )


您的留言將使用 Facebook 帳號。 登出 / 變更 )

Google+ photo

您的留言將使用 Google+ 帳號。 登出 / 變更 )

連結到 %s