Will Vousden
Will Vousden

Reputation: 33358

Vim indenting and alignment: combining spaces and tabs

I'm trying to work out how to get Vim to follow a slightly more complex indentation scheme than most editors allow by default. Essentially I want to use tabs for indentation, but spaces to align statements that span more than one line. For example:

    private static $_columns = array('id' => 'id',
                                     'email' => 'email',
                                     'passwordHash' => 'password_hash',
                                     'salt' => 'salt');
    ^ tabs up to here
                                     ^ spaces up to here

The idea here is that indentation follows the tab-width preferences of whoever is editing the file, while multi-line statements still align correctly.

I guess the simple way to implement this would be to have Vim just copy the indentation pattern used on the previous line (i.e. the leading white space) whenever a new line is entered. Is there any way to do this in Vim? Would I need to write a plugin?

Upvotes: 3

Views: 1513

Answers (1)

Xavier T.
Xavier T.

Reputation: 42228

There is a wikia entry dedicated to that topic : Indent with tabs, align with spaces

The suggested solution is to use a plugin : "Smart Tabs"

Upvotes: 6

Related Questions