Vim: source code formatting

前端 未结 3 717
天涯浪人
天涯浪人 2020-12-10 16:10

Take a look at the enum:

enum TestEnum
{
    First = 1,
    Second = 2,
    Unknown = 3,
    TestTestTest = 100,
    Zero = 0,
    Foo = 123,
}
3条回答
  •  难免孤独
    2020-12-10 16:38

    The Align.vim plugin is probably the way to go, but if you wish to have it handy on a standard installation, you could always filter through awk to get some generic functionality with not too much work.

    For TestEnum you would do something like

    '<,'>!awk '{printf "^I\%-20s\%-20s\%-20s\n", $1, $2, $3}'
    

    after visually selecting the braced contents (viB is awesome here.)

    For Foo you would do

    '<,'>!awk '{printf "^I\%-20s\%-20s\n", $1, $2}'
    

    You could probably make it variable width with an awk for-loop but at the cost of the easy and fast to type version here.

    If you have the unix utility col handy, you might simply try

    '<,'>!col -x
    

    But here your mileage will really vary, as this is not the intended use of the utility.

提交回复
热议问题