How to indent multiple lines starting from the mid

2019-03-03 20:07发布

问题:

For example, to convert this

$example = array(
    'First' => 'This,
    'Second' => 'is',
    'Third' => 'an',
    'Fourth'=> 'example',
    'Fifth' => '.',
);

into this

$example = array(
    'First'     => 'This',
    'Second'    => 'is',
    'Third'     => 'an',
    'Fourth'    => 'example',
    'Fifth'     => '.',
);

without having to indent each => 'whatever', each time.

Is this possible to do in vi?

回答1:

There are two Vim plugins for that, Align and Tabular. With Align, select the lines and execute

:'<,'>Align =>

Tabular is a more recent alternative to the venerable Align, but both offer similar functionality. Pick according to your preferences.



回答2:

As a complement to Ingo's answer, here is how you do it with Tabular:

:'<,'>Tabularize /=>


标签: vim vi