New answers tagged

2

In addition to other answers, look in the docs for \v which, at the beginning of the search string, makes it behave as "very magic", which means that + will work the way you want, while \+ will refer to the literal plus sign.


4

If you read :help pattern, you’ll see you need \+. Vim’s patterns are not quite like PCRE or POSIX B/ERE


3

As it has been explained, this function will always assume 9 submatches can exist and it will return an entry in the result list for all possible submatch. Hence the 5 extra elements returned. On a practical note, this means that we cannot call it this way let [all, a, b, c, end] = matchlist('acd', '\v(a)?(b)?(c)?(.*)') " fails But we don't have to fill 5 ...


4

what's up with those 5 empty strings at the end? matchlist() always returns the list of 10 items (the matched string and nine submatches - just like \0, \1, ..., \9 in :h sub-replace-special). The last five weren't used, so they are set to empty strings.


Top 50 recent answers are included