简体   繁体   中英

Vim auto indent large array litterals

I'm faced with the problem of ugly-looking lists on several lines for which the lines do not have the same length.

Here take this example:

    voxels = [[90, 90,    90],
              [110, 110, 110],
              [40, 40,    40],
              [100, 100, 100],
              [50, 50,    50],
              [25, 25,    25],
              [10, 10,    10]]
    cords = [[-5.141, -114.9, 181.8],
             [-27.71, -99.95, 169.4],
             [51.29, -152.3, 213],
             [-16.43, -107.4, 175.6],
             [40, -144.8, 206.8],
             [68.21, -163.5, 222.3],
             [85.14, -174.7, 231.7]]

voxels list is corretly formatted but cords is not. Couldn't find any vim tool that does this, any ideas on how to get this done?

You can try the Tabular plugin ; once installed, go to the line starting with cords = , then run the following command (the end of the command may be different giving your own taste, see the plugin's help):

:.,.+6Tabularize /,/l0l1

This should give the following result:

cords = [[-5.141, -114.9, 181.8] ,
         [-27.71, -99.95, 169.4] ,
         [51.29 , -152.3, 213]   ,
         [-16.43, -107.4, 175.6] ,
         [40    , -144.8, 206.8] ,
         [68.21 , -163.5, 222.3] ,
         [85.14 , -174.7, 231.7]]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM