Search code examples
regexvimtabular

Have Tabulize ignore some lines and align the others


I would want Tabulize to ignore lines which do not have a particular character and then align/tabularize the lines ..

text1_temp = text_temp;
temporary_line;
text2    = text_temp;

In the end i would like the following :

text1_temp = text_temp;
temporary_line;
text2      = text_temp;

// The 2nd "=" is spaced/tabbed with relation to the first "="

If i run ":Tabularize /=" for the 3 lines together I get :

text1_temp     = text_temp;
temporary_line;
text2          = text_temp;

Where the two lines with "=" are aligned with respect to the length of the middle line

Any suggestions .. ?

PS: I edited the post possibly to explain the need better ..


Solution

  • I am not sure how to do this with Tabular directly. You might be able to use Christian Brabandt's NrrwRgn plugin to filter out only lines with = using :NRP then running :NRM. This will give you a new buffer with only the lines with = so you can run :tabularize/=/ and then save the the buffer (:w, :x, etc).

    :g/=/NRP
    :NRM
    :tabularize/=/
    :x
    

    The easiest option is probably to use vim-easy-align which supports such behavior out of the box it seems. Example of using EasyAlign (Using ga as EasyAlign's mapping you):

    gaip=