How to indent multiple lines starting from the middle in vi?

半世苍凉 提交于 2019-12-02 17:13:04

问题


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 /=>


来源:https://stackoverflow.com/questions/13174568/how-to-indent-multiple-lines-starting-from-the-middle-in-vi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!