-
Notifications
You must be signed in to change notification settings - Fork 1
/
matchlist.vim
78 lines (63 loc) · 987 Bytes
/
matchlist.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
" ..\run_ matchlist
redir > matchlist.out
fu! M(pattern, txt) " {
let l:ml = matchlist(a:txt, a:pattern)
echo ' len (l:ml): ' . len(l:ml)
for i in range(0, len(l:ml)-1)
echo ' ' . i . ': ' . l:ml[i]
endfor
echo ''
endfu " }
call M ('\vfoo(\d+)bar(\d+)baz', 'foobarbaz')
" len (l:ml): 0
call M ('\vfoo(\d+)bar(\d+)baz', 'foo42bar17baz')
" len (l:ml): 10
" 0: foo42bar17baz
" 1: 42
" 2: 17
" 3:
" 4:
" 5:
" 6:
" 7:
" 8:
" 9:
"
call M('\v(\d+)?(\S+)', '20abc')
" len (l:ml): 10
" 0: 20abc
" 1: 20
" 2: abc
" 3:
" 4:
" 5:
" 6:
" 7:
" 8:
" 9:
call M('\v(\d+)?(\S+)', 'def20')
" len (l:ml): 10
" 0: def20
" 1:
" 2: def20
" 3:
" 4:
" 5:
" 6:
" 7:
" 8:
" 9:
call M('\v((\d+)?(\D+)?)', '42xyz')
" len (l:ml): 10
" 0: 42xyz
" 1: 42xyz
" 2: 42
" 3: xyz
" 4:
" 5:
" 6:
" 7:
" 8:
" 9:
redir END
q