Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 954
Will Vousden Avatar asked Nov 29 '25 23:11

Will Vousden


1 Answers

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"

like image 182
Xavier T. Avatar answered Dec 02 '25 16:12

Xavier T.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!