I want to match a rectangle area in Vim using a regex expression, for example:
abcd test1
abcd test2
I want to match test1
and test2
at once, but not abcd
s.
(test1
and test2
are constant, we don't need to consider [0-9]
, that's just an example)
I want to match every column-aligned test1
test2
This
test1
test2
the rectangle area may appear anywhere, I can't assume it is at "column 3" or something of that sort.
If they are not aligned, don't match it.
I tried \1\@<=test1\n\(.*\)\@<=test2
but no luck, because lookahead breaks a group. (from :help \\@<=
)
Does anyone know how to do it with only vim-regex? Thanks.
Edit:
A complicated example may be this one:
aaaaaaaaa
b test1 b
c test2 c
ddddddddd
match only test1
and test2
.
Usin two or more regex is acceptable (one for test1
and the other for test2
?)
Edit2:
This is just for fun, I am just curious about how much vim can achieve, it's not a serious problem, it may be boring and meaningless for many people and that is fine with me, please don't be bothered, good night :)
Simply searching for /test[0-9
] will suffice. But I think the spirit of the question is really more about visual blocks. In visual mode you can use text objects for movement. So, in this case:
w
to visually select the entire word. j
to visually select the next word in the column below the first one. (use a range to extend this rectangular block, e.g. 10j
would visually select the next ten items in that column.) If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With