Aligning text with Tabularize

I am using the Tabularize plugin in Vim and have the following text:

reg [321:123] ip_addr=32'h12345678;
reg [15:0] trie_data=16'h9abc;
reg [2:0] select=3'h5;

wire [3:0] nibble;
wire sram_bit;


which I want to align this way:

reg  [321:123] ip_addr   = 32'h12345678;
reg   [15:0]   trie_data = 16'h9abc;
reg    [2:0]   select    = 3'h5;

wire   [3:0]   nibble;
wire           sram_bit;


In words:

  • left align / wire in the first column
  • align bit width, if any, along ':'
  • left-align names in the third column
  • = characters in 4th column
  • left alignment of the seed values ​​in the 5th column.

So far, I've tried the following in order:

:Tabularize /[[0-9]*:/l1r0l0
:Tabularize /:[0-9]*]/l0l1l0
:Tabularize /=


but this concatenates "wire" and "sram_bit" in the first column instead of putting it in the first and third columns respectively.


source to share

2 answers

With two Tabularize commands, this can be done as follows:

:Tabularize /[[0-9]*:/l1c0l0
:Tabularize /=


So, here you are mainly using [number:

as separator.



Or with Align.vim

:AlignCtrl <>
:AlignCtrl p0
:%Align \S\+

:AlignCtrl p1
:%Align =


I have a feeling there should be an easy way to combine them, but I didn't quite get it right away, so I'll leave it for another day.



All Articles