regex - VIM - "Pretty" column format of structs in C -


i have c code lot of typedef'ed structs, , in vim:

typedef struct {   int         a;   somevalue*    b;   someothervalue* c; } val_t; 

when enable "print whitespace characters" in vim via :set list, see code appears (with . characters denoting spaces, , --> denoting hard tabs):

typedef struct {   int->-->-->-->a;   somevalue*....b;   someothervalue*>>c; } val_t; 

so, seems code has mix of hard-tabs , spaces on place, due different editors being used maintain it. i'm attempting write commands tidy up. know can visual selection via shift+v, pipe off selection col via:

:'<:'>!col 

however, output in vim looks terrible, seems col separating columns "logically" (ie: via 3 hard-tabs), rather lexically, , output looks so:

typedef struct {   int--->--->--->a;   somevalue*>--->--->b;   someothervalue*--->--->--->c; } val_t; 

is there way tell col align columns of data using hard-tabs of fixed width (ie: 4 "spaces" per tab) shown below, beginning of variable names within struct visually align? desired result be:

typedef struct {   int--->--->--->--->a;   somevalue*>--->--->b;   someothervalue*--->c; } val_t; 

this allow me re-factor bunch of header files on per-block/per-struct level rather spending hours manually indenting chunks of code nice.

thank you.

are stuck on hard tabs? if not may want tabular or vim-easy-align.

with tabular can this:

:?{?+,/}/-tabularize/\ze\w\+;/ 

for more see:

:h \ze :h range 

Comments