How to indent multiple lines starting from the mid

2019-03-03 20:11发布

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?

标签: vim vi
2条回答
【Aperson】
2楼-- · 2019-03-03 20:41

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

:'<,'>Tabularize /=>
查看更多
Fickle 薄情
3楼-- · 2019-03-03 21:02

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.

查看更多
登录 后发表回答