3
votes

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?

1
@sidyll: Not quite as neat, and requires more effort! Still, I've never played with modelines before, so I'll go and experiment – thanks!Will Vousden
I agree. I just suggested it as, in some cases, when you know that the receiver will read the file in Vim, a simple vim:ts=4 works nicely.sidyll

1 Answers

6
votes

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"