Vim corresponds to a rectangular area

I want to align a rectangular region in Vim with regex, for example:

abcd test1 abcd test2 

I want to combine test1 and test2 once, but not abcd s. ( test1 and test2 are constant, we do not need to consider [0-9] , which is just an example)

I want to match each column-aligned test1 test2

it

 test1 test2 

the rectangle area can appear anywhere, I canโ€™t guess it in column โ€œ3โ€ or something like that.

If they are not aligned, do not match.

I tried \1\@<=test1\n\(.*\)\@<=test2 , but no luck, because lookahead splits the group. (from :help \\@<= )

Does anyone know how to do this only with vim-regex? Thanks.


Edit:

The most complex example may be in this case:

 aaaaaaaaa b test1 b c test2 c ddddddddd 

matches only test1 and test2 .

You can use two or more regular expressions (one for test1 and one for test2 ?)


Edit2:

Itโ€™s just for fun, Iโ€™m just wondering how much vim can achieve, itโ€™s not a serious problem, it can be boring and pointless for many people, and itโ€™s good for me, please donโ€™t worry, good night :)

+6
source share
1 answer

Try the following to find the match that suits you. Syntax /somethingWeAreLooking\(_.\)*followedByTheOtherThing

In this case, it will be like this:

/test\(_.\)*[1-9]

0
source

Source: https://habr.com/ru/post/980602/


All Articles