Reputation: 519
I'm learning about the Vim Pattern, and really confused about the column position matching definition. Below I do very simple test.
Just create a file, in the first line first column type: 123456789
.
Just make me easy to track the column number where each digit locate.
Then I search /.\%>3c.*\%<8c
, it matches 3456
and seems reasonable, because as the document explain \%<8c
will match the 7th column and it's zero-width match so it will only match up to 6.
But then I search /\%>3c.*\%<8c
, this time Vim matches 4567
. So why this time it matches 7??? It seems unreasonable.
My Vim version is up-to-date: 7.4 Included patches: 1-884.
Upvotes: 6
Views: 1815
Reputation: 12895
If your aim is to search for column positions greater than 3 and less than 8, you don't need dots or stars, this suffices:
/\%>3\%<8
If you question is about the unintuitive behavior of adding both dots and/or stars to your search, then yes it is confusing. I believe in this case, the star is superfluous. You can get the same behavior you see (numbers 4-6 found) by just searching for:
/\%>3.\%<8
I believe the dot is considered a restrictive criteria for the search. In other words, there must be a char proceeding the column position. So the search routine runs something like this: is there a column position 4 with a character in 5th position? yes, add it to the result; is there is column position 6 with a char in position 7? yes, add it; is there a column position 7 with a char in 8th position? No -- because the zero-width criteria of not including 8th position or beyond (\%<8). To include the char in eight-position, you can add another dot after 8c and then 4-7 will be found, e.g.:
/\%3c.\%<8c.
But, note, this just gets us back to my first example:
/\%>3\%<8 <=> /\%3c.\%<8c.
Upvotes: 1
Reputation: 519
I think I may have got the answer. Actually there are two matches, the first match is 456, the second match is empty string at column 7. When set hlsearch, it will highlight 4567, since the second match is empty string match at column 7, in order to make the match noticeable, vim will also highlight the character at that column. This is what I guess, please correct me if I'm wrong.
Upvotes: 0