How do I change tab size in Vim?

alexchenco picture alexchenco · Jan 13, 2010 · Viewed 250.4k times · Source

Every time I add a selector in CSS and I press Enter to define the properties it ends up like this:

#selector {
        property: value;
}

(8-space tabs)

How can I configure Vim to make it like this:

#selector {
    property: value;
}

(4-space tabs)

Answer

zoul picture zoul · Jan 13, 2010
:set tabstop=4
:set shiftwidth=4
:set expandtab

This will insert four spaces instead of a tab character. Spaces are a bit more “stable”, meaning that text indented with spaces will show up the same in the browser and any other application.